Skip to content

Commit

Permalink
fix: Improved error logging and updated Cobra to v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-cardenas-coding committed Jul 7, 2020
1 parent 025ec13 commit 3ad01a8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 42 deletions.
21 changes: 11 additions & 10 deletions cmd/disaster.go
@@ -1,6 +1,7 @@
package cmd

import (
"fmt"
"os"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -33,25 +34,25 @@ var rootCmd = &cobra.Command{
err := doc.GenMarkdownTree(cmd, "./documentation/")
if err != nil {
log.WithFields(log.Fields{
"package": "cmd",
"file": "disaster.go",
"package": "cmd",
"file": "disaster.go",
"parent_function": "generateDocFlag",
"function": "doc.GenMarkdownTree"
"error": err,
"data": fmt.Sprint(cmd, "./documentation/"),
"function": "doc.GenMarkdownTree",
"error": err,
"data": fmt.Sprint(cmd, "./documentation/"),
}).Fatal("Error generating markdown content", ISSUE_MSG)
}
}

err := cmd.Help()
if err != nil {
log.WithFields(log.Fields{
"package": "cmd",
"file": "disaster.go",
"package": "cmd",
"file": "disaster.go",
"parent_function": "generateDocFlag",
"function": "cmd.Help",
"error": err,
"data": nil,
"function": "cmd.Help",
"error": err,
"data": nil,
}).Fatal("Error outputting help!", ISSUE_MSG)
}
},
Expand Down
64 changes: 32 additions & 32 deletions cmd/update.go
Expand Up @@ -77,12 +77,12 @@ func getSystemPathForDisaster() string {
path, err := os.Executable()
if err != nil {
log.WithFields(log.Fields{
"package": "cmd",
"file": "update.go",
"package": "cmd",
"file": "update.go",
"parent_function": "getSystemPathForDisaster",
"function": "os.Executable",
"error": err,
"data": nil,
"function": "os.Executable",
"error": err,
"data": nil,
}).Error("Error getting system path", ISSUE_MSG)
}
return path
Expand All @@ -103,13 +103,13 @@ func checkForNewRelease() (bool, error) {
resp, err := client.Do(req)
if err != nil {
log.WithFields(log.Fields{
"package": "cmd",
"file": "update.go",
"package": "cmd",
"file": "update.go",
"parent_function": "checkForNewRelease",
"function": "client.Do",
"error": err,
"data": nil,
}).Fatal("Error initaiting connection to, ",url, ISSUE_MSG)
"function": "client.Do",
"error": err,
"data": nil,
}).Fatal("Error initaiting connection to, ", url, ISSUE_MSG)
}
defer resp.Body.Close()

Expand All @@ -118,12 +118,12 @@ func checkForNewRelease() (bool, error) {
// Unmarshal the JSON to the Github Release strcut
if err := json.NewDecoder(resp.Body).Decode(&release); err != nil {
log.WithFields(log.Fields{
"package": "cmd",
"file": "update.go",
"package": "cmd",
"file": "update.go",
"parent_function": "checkForNewRelease",
"function": "json.NewDecoder",
"error": err,
"data": nil,
"function": "json.NewDecoder",
"error": err,
"data": nil,
}).Fatal("Error unmarshalling Github response", ISSUE_MSG)
}

Expand Down Expand Up @@ -151,12 +151,12 @@ func getReleaseURL() (string, string, error) {
resp, err := client.Do(req)
if err != nil {
log.WithFields(log.Fields{
"package": "cmd",
"file": "update.go",
"package": "cmd",
"file": "update.go",
"parent_function": "getReleaseURL",
"function": "client.Do",
"error": err,
"data": req,
"function": "client.Do",
"error": err,
"data": req,
}).Fatal("Error connecting to the Github API", ISSUE_MSG)
}
defer resp.Body.Close()
Expand All @@ -166,12 +166,12 @@ func getReleaseURL() (string, string, error) {
// Unmarshal the JSON to the Github Release strcut
if err := json.NewDecoder(resp.Body).Decode(&release); err != nil {
log.WithFields(log.Fields{
"package": "cmd",
"file": "update.go",
"package": "cmd",
"file": "update.go",
"parent_function": "getReleaseURL",
"function": "client.Do",
"error": err,
"data": req,
"function": "client.Do",
"error": err,
"data": req,
}).Error("Error unmarshaling Github Release data.", ISSUE_MSG)
}

Expand Down Expand Up @@ -291,7 +291,7 @@ func DownloadFile(filePath string, url string) error {
"parent_function": "DownloadFile",
"function": "os.Create",
"error": err,
"data": fmt.Sprint((tmpDir + pathOSeperator + "download.tmp"),
"data": fmt.Sprint((tmpDir + pathOSeperator + "download.tmp")),
}).Error("Error creating temp directory.", ISSUE_MSG)
return err
}
Expand Down Expand Up @@ -491,12 +491,12 @@ func DownloadFile(filePath string, url string) error {
err := os.Rename("disaster.tmp", "disaster")
if err != nil {
log.WithFields(log.Fields{
"package": "cmd",
"file": "update.go",
"package": "cmd",
"file": "update.go",
"parent_function": "DownloadFile",
"function": "os.Rename"
"error": err,
"data": "disaster.tmp, disaster",
"function": "os.Rename",
"error": err,
"data": "disaster.tmp, disaster",
}).Fatal("Rename failed:", ISSUE_MSG)
return err
}
Expand Down

0 comments on commit 3ad01a8

Please sign in to comment.