Skip to content

Commit

Permalink
Merge pull request #14 from timperrett/errors
Browse files Browse the repository at this point in the history
Output errors when they happen
  • Loading branch information
timperrett authored Oct 14, 2018
2 parents 1ae05e4 + 3ce55d6 commit 7c9db98
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ func main() {

deployable, e := newProtoDeployable(ctr, name, tag)
if e != nil {
return cli.NewMultiError(e...)
printTerminalErrors(e)
return cli.NewExitError("Fatal error whilst generating NLDP format.", 1)
}
data, ex := proto.Marshal(deployable)
if ex != nil {
Expand Down Expand Up @@ -420,7 +421,8 @@ func main() {
} else {
deployment, _, errors := gh.Repositories.CreateDeployment(owner, reponame, &r)
if errors != nil {
return cli.NewMultiError(errors)
printTerminalErrors([]error{errors})
return cli.NewExitError("Fatal error encountered whilst creating deployment.", 1)
}
fmt.Println("Created deployment " + strconv.Itoa(*deployment.ID) + " on " + owner + "/" + reponame)
}
Expand Down
11 changes: 11 additions & 0 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"errors"
"fmt"
"io/ioutil"
"os"
"regexp"
Expand Down Expand Up @@ -140,3 +141,13 @@ func newProtoDeployable(imageUri string, unitName string, tag string) (*nelson.D
},
}, nil
}

func printTerminalErrors(errs []error) {
for i, j := 0, len(errs)-1; i < j; i, j = i+1, j-1 {
errs[i], errs[j] = errs[j], errs[i]
}

for _, e := range errs {
fmt.Println(e)
}
}

0 comments on commit 7c9db98

Please sign in to comment.