Skip to content

Commit

Permalink
Improve error messaging (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
puthrayaharness authored Mar 23, 2023
1 parent 071d488 commit 6a61045
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func handleResp(req *http.Request) (respBodyObj ResponseBody, err error) {
}).Debug("The response body")
err = json.Unmarshal(respBody, &respBodyObj)
if err != nil {
log.Fatalln("There was error while parsing the response from server. Exiting...")
log.Fatalln("There was error while parsing the response from server. Exiting...", err)
}
if resp.StatusCode != 200 {
if len(respBodyObj.Message) > 0 {
Expand Down
10 changes: 5 additions & 5 deletions entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ func QueueCreateEntity(body RequestBody) (reqId string, err error) {
url := GetUrl(migrationReq.Environment, MIGRATOR, "save/async", migrationReq.Account)
resp, err := Post(url, migrationReq.Auth, body)
if err != nil {
log.Fatal("Failed to create the entities")
log.Fatal("Failed to create the entities", err)
}
resource, err := getResource(resp.Resource)
if err != nil || len(resource.RequestId) == 0 {
log.Fatal("Failed to create the entities")
log.Fatal("Failed to create the entities", err)
return
}
reqId = resource.RequestId
Expand All @@ -48,12 +48,12 @@ func PollForCompletion(reqId string) {
resp, err := Get(url, migrationReq.Auth)
if err != nil {
s.Stop()
log.Fatal("Failed to create the entities")
log.Fatal("Failed to create the entities", err)
}
resource, err := getResource(resp.Resource)
if err != nil {
s.Stop()
log.Fatal("Failed to create the entities")
log.Fatal("Failed to create the entities", err)
}
if resource.Status == "ERROR" {
s.Stop()
Expand All @@ -63,7 +63,7 @@ func PollForCompletion(reqId string) {
s.Stop()
saveSummary, err := getSaveSummary(resource)
if err != nil {
log.Fatal("Failed to create the entities")
log.Fatal("Failed to create the entities", err)
}
renderSaveSummary(saveSummary)
break
Expand Down
8 changes: 7 additions & 1 deletion projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ func bulkCreateProject(*cli.Context) error {
promptConfirm := PromptDefaultInputs()
promptConfirm = PromptOrgAndProject([]string{Org}) || promptConfirm

if len(migrationReq.ExportFolderPath) == 0 {
migrationReq.ExportFolderPath = TextInput("Where would you like to export the generated files?")
promptConfirm = true
}

log.WithFields(log.Fields{
"Account": migrationReq.Account,
"OrgIdentifier": migrationReq.OrgIdentifier,
"Export folder": migrationReq.ExportFolderPath,
}).Info("Bulk Project creation details")

if promptConfirm {
Expand All @@ -89,7 +95,7 @@ func bulkCreateProject(*cli.Context) error {
})

if err != nil {
log.Fatal("There was an error creating the projects")
log.Fatal("There was an error creating the projects", err)
return err
}

Expand Down
3 changes: 2 additions & 1 deletion release.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func printUpgradeMessage(from string, to string) {
green := color.New(color.FgGreen).SprintFunc()
red := color.New(color.FgHiRed).SprintFunc()
yellow := color.New(color.FgYellow).SprintFunc()
fmt.Printf("[%s] A new release of harness-upgrade available: %s -> %s\n", blue("notice"), red(from), green(to))
fmt.Printf("[%s] A new release of harness-upgrade is available: %s %s\n", blue("notice"), red(from), green(to))
fmt.Printf("%s\n", yellow("https://github.com/harness/migrator/releases/tag/"+to))
fmt.Printf("To update, run: %s\n", green("harness-upgrade update"))
}
12 changes: 6 additions & 6 deletions summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ func GetAppSummary(*cli.Context) error {
func handleSummary(url string) error {
resp, err := Get(url, migrationReq.Auth)
if err != nil {
log.Fatal("Failed to fetch account summary")
log.Fatal("Failed to fetch account summary", err)
}
resource, err := getResource(resp.Resource)
if err != nil || len(resource.RequestId) == 0 {
log.Fatal("Failed to fetch account summary")
log.Fatal("Failed to fetch account summary", err)
return err
}
reqId := resource.RequestId
Expand All @@ -54,23 +54,23 @@ func handleSummary(url string) error {
resp, err := Get(url, migrationReq.Auth)
if err != nil {
s.Stop()
log.Fatal("Failed to fetch account summary")
log.Fatal("Failed to fetch account summary", err)
}
resource, err := getResource(resp.Resource)
if err != nil {
s.Stop()
log.Fatal("Failed to fetch account summary")
log.Fatal("Failed to fetch account summary", err)
}
if resource.Status == "ERROR" {
s.Stop()
log.Fatal("Failed to fetch account summary")
log.Fatal("Failed to fetch account summary", err)
}
if resource.Status == "DONE" {
s.Stop()
summary, err := getSummary(resource)
if err != nil {
s.Stop()
log.Fatal("Failed to fetch account summary")
log.Fatal("Failed to fetch account summary", err)
}
renderSummary(summary.Summary)
break
Expand Down
6 changes: 3 additions & 3 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func Update(*cli.Context) (err error) {
}
url := fmt.Sprintf("https://github.com/harness/migrator/releases/download/%s/harness-upgrade-%s-%s-%s.%s", newVersion, newVersion, GOOS, GOARCH, extension)

if GOOS != "darwin" {
fmt.Printf("%s\n", yellow("Auto update support is only available for MacOS right now"))
if GOOS == "windows" {
fmt.Printf("%s\n", yellow("Auto update support is not available for windows"))
fmt.Printf("Download the following release - %s\n", blue(url))
return nil
}
Expand Down Expand Up @@ -89,7 +89,7 @@ func readTar(body io.ReadCloser, dest string) error {
if header.Typeflag == tar.TypeReg && header.Name == "harness-upgrade" {
execFile := path.Join(dest, header.Name)
green := color.New(color.FgGreen).SprintFunc()
fmt.Printf("Extracking harness-upgrade to - %s\n", green(execFile))
fmt.Printf("Extracting harness-upgrade to - %s\n", green(execFile))
outFile, err := os.Create(execFile)
if err != nil {
return err
Expand Down

0 comments on commit 6a61045

Please sign in to comment.