Skip to content

Commit

Permalink
use go 1.13 errors everywhere and better error message from kubectl a…
Browse files Browse the repository at this point in the history
…pply (#6)
  • Loading branch information
VJftw committed Jan 17, 2020
1 parent 38eb6bf commit c198e1c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
2 changes: 0 additions & 2 deletions pkg/kubernetes/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go_library(
],
visibility = ["PUBLIC"],
deps = [
"//third_party/go:pkg_errors",
],
)

Expand All @@ -16,7 +15,6 @@ go_test(
],
deps = [
":kubernetes",
"//third_party/go:pkg_errors",
"//third_party/go:stretchr_testify",
],
)
13 changes: 4 additions & 9 deletions pkg/kubernetes/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"io"
"log"
"os/exec"

"github.com/pkg/errors"
)

// KubectlOpts represents options/flags to pass to kubectl
Expand All @@ -21,7 +19,7 @@ func Apply(resources string, opts *KubectlOpts) error {
cmd := exec.Command(shCmd[0], shCmd[1:]...)
stdin, err := cmd.StdinPipe()
if err != nil {
return errors.Wrap(err, "could not create stdin pipe")
return fmt.Errorf("could not create stdin pipe: %w", err)
}
go func() {
defer stdin.Close()
Expand All @@ -32,13 +30,10 @@ func Apply(resources string, opts *KubectlOpts) error {
}()

output, err := cmd.CombinedOutput()
if err != nil {
return errors.Wrap(err, resources)
}
if !cmd.ProcessState.Success() {
return errors.Wrap(err, string(output))
if err != nil || !cmd.ProcessState.Success() {
return fmt.Errorf("%s\n%s:%w", resources, output, err)
}
log.Println(string(output))
log.Printf("%s\n", output)
return nil
}

Expand Down
1 change: 0 additions & 1 deletion pkg/putil/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ go_library(
deps = [
"//pkg/genproto/v1",
"//third_party/go:gogo_protobuf",
"//third_party/go:pkg_errors",
],
)
4 changes: 2 additions & 2 deletions pkg/putil/write.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package putil

import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"

"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
v1 "github.com/thought-machine/dracon/pkg/genproto/v1"
)

Expand Down Expand Up @@ -56,7 +56,7 @@ func WriteResults(
}

if err := ioutil.WriteFile(outFile, outBytes, 0644); err != nil {
return errors.Wrapf(err, "could not write to file %s", outFile)
return fmt.Errorf("could not write to file '%s': %w", outFile, err)
}

log.Printf("wrote %d issues from to %s", len(issues), outFile)
Expand Down

0 comments on commit c198e1c

Please sign in to comment.