Skip to content

Commit

Permalink
Handle error
Browse files Browse the repository at this point in the history
  • Loading branch information
babarot committed Apr 29, 2018
1 parent eb46cb1 commit d20cc28
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ func (cfg *Config) Register(s Service) error {
if err := json.Indent(&out, b, "", " "); err != nil {
return err
}
file, _ := os.OpenFile(cfg.path, os.O_WRONLY, 0644)
file, err := os.OpenFile(cfg.path, os.O_WRONLY, 0644)
if err != nil {
return err
}
w := bufio.NewWriter(file)
w.Write(out.Bytes())
return w.Flush()
Expand Down
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ func newCLI(args []string) CLI {

func (c CLI) exit(msg interface{}) int {
switch m := msg.(type) {
case int:
return m
case nil:
return 0
case string:
fmt.Fprintf(c.stdout, "%s\n", m)
return 0
case error:
fmt.Fprintf(c.stderr, "[ERROR] %s: %s\n", app, m.Error())
return 1
case int:
return m
case nil:
return 0
default:
panic(msg)
}
Expand Down Expand Up @@ -144,8 +144,8 @@ func (c CLI) run() int {

authHeader := fmt.Sprintf("'Authorization: Bearer %s'", token)
args := append(
[]string{"-H", authHeader}, // For IAP header
c.args..., // Original args
[]string{"-H", authHeader}, // For IAP
c.args...,
)
args = append(args, url)

Expand Down

0 comments on commit d20cc28

Please sign in to comment.