Skip to content

Commit 3ad01a8

Browse files
fix: Improved error logging and updated Cobra to v1.0.0
1 parent 025ec13 commit 3ad01a8

File tree

2 files changed

+43
-42
lines changed

2 files changed

+43
-42
lines changed

cmd/disaster.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"fmt"
45
"os"
56

67
log "github.com/sirupsen/logrus"
@@ -33,25 +34,25 @@ var rootCmd = &cobra.Command{
3334
err := doc.GenMarkdownTree(cmd, "./documentation/")
3435
if err != nil {
3536
log.WithFields(log.Fields{
36-
"package": "cmd",
37-
"file": "disaster.go",
37+
"package": "cmd",
38+
"file": "disaster.go",
3839
"parent_function": "generateDocFlag",
39-
"function": "doc.GenMarkdownTree"
40-
"error": err,
41-
"data": fmt.Sprint(cmd, "./documentation/"),
40+
"function": "doc.GenMarkdownTree",
41+
"error": err,
42+
"data": fmt.Sprint(cmd, "./documentation/"),
4243
}).Fatal("Error generating markdown content", ISSUE_MSG)
4344
}
4445
}
4546

4647
err := cmd.Help()
4748
if err != nil {
4849
log.WithFields(log.Fields{
49-
"package": "cmd",
50-
"file": "disaster.go",
50+
"package": "cmd",
51+
"file": "disaster.go",
5152
"parent_function": "generateDocFlag",
52-
"function": "cmd.Help",
53-
"error": err,
54-
"data": nil,
53+
"function": "cmd.Help",
54+
"error": err,
55+
"data": nil,
5556
}).Fatal("Error outputting help!", ISSUE_MSG)
5657
}
5758
},

cmd/update.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ func getSystemPathForDisaster() string {
7777
path, err := os.Executable()
7878
if err != nil {
7979
log.WithFields(log.Fields{
80-
"package": "cmd",
81-
"file": "update.go",
80+
"package": "cmd",
81+
"file": "update.go",
8282
"parent_function": "getSystemPathForDisaster",
83-
"function": "os.Executable",
84-
"error": err,
85-
"data": nil,
83+
"function": "os.Executable",
84+
"error": err,
85+
"data": nil,
8686
}).Error("Error getting system path", ISSUE_MSG)
8787
}
8888
return path
@@ -103,13 +103,13 @@ func checkForNewRelease() (bool, error) {
103103
resp, err := client.Do(req)
104104
if err != nil {
105105
log.WithFields(log.Fields{
106-
"package": "cmd",
107-
"file": "update.go",
106+
"package": "cmd",
107+
"file": "update.go",
108108
"parent_function": "checkForNewRelease",
109-
"function": "client.Do",
110-
"error": err,
111-
"data": nil,
112-
}).Fatal("Error initaiting connection to, ",url, ISSUE_MSG)
109+
"function": "client.Do",
110+
"error": err,
111+
"data": nil,
112+
}).Fatal("Error initaiting connection to, ", url, ISSUE_MSG)
113113
}
114114
defer resp.Body.Close()
115115

@@ -118,12 +118,12 @@ func checkForNewRelease() (bool, error) {
118118
// Unmarshal the JSON to the Github Release strcut
119119
if err := json.NewDecoder(resp.Body).Decode(&release); err != nil {
120120
log.WithFields(log.Fields{
121-
"package": "cmd",
122-
"file": "update.go",
121+
"package": "cmd",
122+
"file": "update.go",
123123
"parent_function": "checkForNewRelease",
124-
"function": "json.NewDecoder",
125-
"error": err,
126-
"data": nil,
124+
"function": "json.NewDecoder",
125+
"error": err,
126+
"data": nil,
127127
}).Fatal("Error unmarshalling Github response", ISSUE_MSG)
128128
}
129129

@@ -151,12 +151,12 @@ func getReleaseURL() (string, string, error) {
151151
resp, err := client.Do(req)
152152
if err != nil {
153153
log.WithFields(log.Fields{
154-
"package": "cmd",
155-
"file": "update.go",
154+
"package": "cmd",
155+
"file": "update.go",
156156
"parent_function": "getReleaseURL",
157-
"function": "client.Do",
158-
"error": err,
159-
"data": req,
157+
"function": "client.Do",
158+
"error": err,
159+
"data": req,
160160
}).Fatal("Error connecting to the Github API", ISSUE_MSG)
161161
}
162162
defer resp.Body.Close()
@@ -166,12 +166,12 @@ func getReleaseURL() (string, string, error) {
166166
// Unmarshal the JSON to the Github Release strcut
167167
if err := json.NewDecoder(resp.Body).Decode(&release); err != nil {
168168
log.WithFields(log.Fields{
169-
"package": "cmd",
170-
"file": "update.go",
169+
"package": "cmd",
170+
"file": "update.go",
171171
"parent_function": "getReleaseURL",
172-
"function": "client.Do",
173-
"error": err,
174-
"data": req,
172+
"function": "client.Do",
173+
"error": err,
174+
"data": req,
175175
}).Error("Error unmarshaling Github Release data.", ISSUE_MSG)
176176
}
177177

@@ -291,7 +291,7 @@ func DownloadFile(filePath string, url string) error {
291291
"parent_function": "DownloadFile",
292292
"function": "os.Create",
293293
"error": err,
294-
"data": fmt.Sprint((tmpDir + pathOSeperator + "download.tmp"),
294+
"data": fmt.Sprint((tmpDir + pathOSeperator + "download.tmp")),
295295
}).Error("Error creating temp directory.", ISSUE_MSG)
296296
return err
297297
}
@@ -491,12 +491,12 @@ func DownloadFile(filePath string, url string) error {
491491
err := os.Rename("disaster.tmp", "disaster")
492492
if err != nil {
493493
log.WithFields(log.Fields{
494-
"package": "cmd",
495-
"file": "update.go",
494+
"package": "cmd",
495+
"file": "update.go",
496496
"parent_function": "DownloadFile",
497-
"function": "os.Rename"
498-
"error": err,
499-
"data": "disaster.tmp, disaster",
497+
"function": "os.Rename",
498+
"error": err,
499+
"data": "disaster.tmp, disaster",
500500
}).Fatal("Rename failed:", ISSUE_MSG)
501501
return err
502502
}

0 commit comments

Comments
 (0)