Skip to content

Commit

Permalink
dev: Fix import path of xerrors package
Browse files Browse the repository at this point in the history
  • Loading branch information
htdvisser committed May 6, 2019
1 parent b89085b commit 2a9784d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
6 changes: 3 additions & 3 deletions .mage/git.go
Expand Up @@ -23,7 +23,7 @@ import (

"github.com/TheThingsIndustries/magepkg/git"
"github.com/magefile/mage/mg"
"golang.org/x/exp/errors"
"golang.org/x/xerrors"
)

// Git namespace.
Expand Down Expand Up @@ -136,7 +136,7 @@ func (Git) commitMsg(messageFile string) error {
commitMsg := s.Text()

if commitMsg == "" {
return errors.New("commit message must not be empty")
return xerrors.New("commit message must not be empty")
}

if strings.HasPrefix(commitMsg, "fixup! ") || strings.HasPrefix(commitMsg, "Merge ") {
Expand All @@ -146,7 +146,7 @@ func (Git) commitMsg(messageFile string) error {
// Check length:
switch {
case len(commitMsg) > 72:
return errors.New("commit message must be shorter than 72 characters")
return xerrors.New("commit message must be shorter than 72 characters")
case len(commitMsg) > 50:
// TODO: Warn.
}
Expand Down
33 changes: 16 additions & 17 deletions .mage/proto.go
Expand Up @@ -25,8 +25,7 @@ import (
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
"github.com/magefile/mage/target"
"golang.org/x/exp/errors"
errfmt "golang.org/x/exp/errors/fmt"
"golang.org/x/xerrors"
)

const (
Expand All @@ -43,7 +42,7 @@ type Proto mg.Namespace
func (Proto) Image(context.Context) error {
out, err := sh.Output("docker", "images", "-q", fmt.Sprintf("%s:%s", protocName, protocVersion))
if err != nil {
return errfmt.Errorf("failed to query docker images: %s", err)
return xerrors.Errorf("failed to query docker images: %s", err)
}
if len(out) > 0 {
return nil
Expand All @@ -61,11 +60,11 @@ func makeProtoc() (func(...string) error, *protocContext, error) {

wd, err := os.Getwd()
if err != nil {
return nil, nil, errfmt.Errorf("failed to get working directory: %w", err)
return nil, nil, xerrors.Errorf("failed to get working directory: %w", err)
}
usr, err := user.Current()
if err != nil {
return nil, nil, errfmt.Errorf("failed to get user: %w", err)
return nil, nil, xerrors.Errorf("failed to get user: %w", err)
}
return sh.RunCmd("docker", "run",
"--rm",
Expand All @@ -86,7 +85,7 @@ func makeProtoc() (func(...string) error, *protocContext, error) {
func withProtoc(f func(pCtx *protocContext, protoc func(...string) error) error) error {
protoc, pCtx, err := makeProtoc()
if err != nil {
return errors.New("failed to construct protoc command")
return xerrors.New("failed to construct protoc command")
}
return f(pCtx, protoc)
}
Expand All @@ -106,26 +105,26 @@ func (p Proto) Go(context.Context) error {
fmt.Sprintf("--grpc-gateway_out=%s:%s", convStr, protocOut),
fmt.Sprintf("%s/api/*.proto", pCtx.WorkingDirectory),
); err != nil {
return errfmt.Errorf("failed to generate protos: %w", err)
return xerrors.Errorf("failed to generate protos: %w", err)
}
return nil
}); err != nil {
return err
}

if err := sh.RunV(filepath.Join(".mage", "scripts", "fix-grpc-gateway-names.sh"), "api"); err != nil {
return errfmt.Errorf("failed to fix gRPC-gateway names: %w", err)
return xerrors.Errorf("failed to fix gRPC-gateway names: %w", err)
}

ttnpb, err := filepath.Abs(filepath.Join("pkg", "ttnpb"))
if err != nil {
return errfmt.Errorf("failed to construct absolute path to pkg/ttnpb: %w", err)
return xerrors.Errorf("failed to construct absolute path to pkg/ttnpb: %w", err)
}
if err := execGo("run", "golang.org/x/tools/cmd/goimports", "-w", ttnpb); err != nil {
return errfmt.Errorf("failed to run goimports on generated code: %w", err)
return xerrors.Errorf("failed to run goimports on generated code: %w", err)
}
if err := execGo("run", "github.com/mdempsky/unconvert", "-apply", ttnpb); err != nil {
return errfmt.Errorf("failed to run unconvert on generated code: %w", err)
return xerrors.Errorf("failed to run unconvert on generated code: %w", err)
}
return sh.RunV("gofmt", "-w", "-s", ttnpb)
}
Expand All @@ -152,7 +151,7 @@ func (p Proto) GoClean(context.Context) error {
func (p Proto) Swagger(context.Context) error {
changed, err := target.Glob(filepath.Join("api", "api.swagger.json"), filepath.Join("api", "*.proto"))
if err != nil {
return errfmt.Errorf("failed checking modtime: %w", err)
return xerrors.Errorf("failed checking modtime: %w", err)
}
if !changed {
return nil
Expand All @@ -162,7 +161,7 @@ func (p Proto) Swagger(context.Context) error {
fmt.Sprintf("--swagger_out=allow_merge,merge_file_name=api:%s/api", pCtx.WorkingDirectory),
fmt.Sprintf("%s/api/*.proto", pCtx.WorkingDirectory),
); err != nil {
return errfmt.Errorf("failed to generate protos: %w", err)
return xerrors.Errorf("failed to generate protos: %w", err)
}
return nil
})
Expand All @@ -177,7 +176,7 @@ func (p Proto) SwaggerClean(context.Context) error {
func (p Proto) Markdown(context.Context) error {
changed, err := target.Glob(filepath.Join("api", "api.md"), filepath.Join("api", "*.proto"))
if err != nil {
return errfmt.Errorf("failed checking modtime: %w", err)
return xerrors.Errorf("failed checking modtime: %w", err)
}
if !changed {
return nil
Expand All @@ -187,7 +186,7 @@ func (p Proto) Markdown(context.Context) error {
fmt.Sprintf("--doc_opt=%s/api/api.md.tmpl,api.md --doc_out=%s/api", pCtx.WorkingDirectory, pCtx.WorkingDirectory),
fmt.Sprintf("%s/api/*.proto", pCtx.WorkingDirectory),
); err != nil {
return errfmt.Errorf("failed to generate protos: %w", err)
return xerrors.Errorf("failed to generate protos: %w", err)
}
return nil
})
Expand All @@ -202,7 +201,7 @@ func (p Proto) MarkdownClean(context.Context) error {
func (p Proto) JsSDK(context.Context) error {
changed, err := target.Glob(filepath.Join("sdk", "js", "generated", "api.json"), filepath.Join("api", "*.proto"))
if err != nil {
return errfmt.Errorf("failed checking modtime: %w", err)
return xerrors.Errorf("failed checking modtime: %w", err)
}
if !changed {
return nil
Expand All @@ -212,7 +211,7 @@ func (p Proto) JsSDK(context.Context) error {
fmt.Sprintf("--doc_opt=json,api.json --doc_out=%s/sdk/js/generated", pCtx.WorkingDirectory),
fmt.Sprintf("%s/api/*.proto", pCtx.WorkingDirectory),
); err != nil {
return errfmt.Errorf("failed to generate protos: %w", err)
return xerrors.Errorf("failed to generate protos: %w", err)
}
return nil
})
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -84,10 +84,10 @@ require (
go.thethings.network/lorawan-stack-legacy v0.0.0-20190118141410-68812c833a78
gocloud.dev v0.12.0
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a
golang.org/x/exp/errors v0.0.0-20190426045226-199475d76704
golang.org/x/net v0.0.0-20190424112056-4829fb13d2c6
golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a
golang.org/x/tools v0.0.0-20190417005754-4ca4b55e2050
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373
google.golang.org/genproto v0.0.0-20190415143225-d1146b9035b9
google.golang.org/grpc v1.20.0
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -753,6 +753,8 @@ golang.org/x/tools v0.0.0-20190417005754-4ca4b55e2050 h1:F2v+dqex82KbcdFuJrgIWjW
golang.org/x/tools v0.0.0-20190417005754-4ca4b55e2050/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/xerrors v0.0.0-20190129162528-20feca13ea86 h1:kMgZCSynBSIN3PHpvuFeMExQwPWtUZ/xfnt2Yr2cp20=
golang.org/x/xerrors v0.0.0-20190129162528-20feca13ea86/go.mod h1:/lyp46tcDBI65C0XC8F4d0/XVb7MT7RScVRech7dX/4=
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373 h1:PPwnA7z1Pjf7XYaBP9GL1VAMZmcIWyFz7QCMSIIa3Bg=
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gonum.org/v1/gonum v0.0.0-20181121035319-3f7ecaa7e8ca/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo=
gonum.org/v1/netlib v0.0.0-20181029234149-ec6d1f5cefe6/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw=
google.golang.org/api v0.0.0-20180603000442-8e296ef26005/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
Expand Down

0 comments on commit 2a9784d

Please sign in to comment.