From f37c253ae4f3b80a42edacea1434a7928f8108cc Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Tue, 4 Jan 2022 22:34:30 -0800 Subject: [PATCH] =?UTF-8?q?commands:=20provide=20more=20helpful=20error=20?= =?UTF-8?q?when=20=E2=80=94build-context=20is=20not=20supported?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tonis Tiigi --- commands/build.go | 29 +++++++++++++++++++++++++++++ go.mod | 1 + vendor/modules.txt | 1 + 3 files changed, 31 insertions(+) diff --git a/commands/build.go b/commands/build.go index fdfc1b39..2861820c 100644 --- a/commands/build.go +++ b/commands/build.go @@ -27,11 +27,13 @@ import ( "github.com/moby/buildkit/session/auth/authprovider" "github.com/moby/buildkit/solver/errdefs" "github.com/moby/buildkit/util/appcontext" + "github.com/moby/buildkit/util/grpcerrors" "github.com/morikuni/aec" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/pflag" + "google.golang.org/grpc/codes" ) const defaultTargetName = "default" @@ -217,6 +219,7 @@ func runBuild(dockerCli command.Cli, in buildOptions) (err error) { } imageID, err := buildTargets(ctx, dockerCli, map[string]build.Options{defaultTargetName: opts}, in.progress, contextPathHash, in.builder, in.metadataFile) + err = wrapBuildError(err) if err != nil { return err } @@ -492,3 +495,29 @@ func parseContextNames(values []string) (map[string]string, error) { } return result, nil } + +func wrapBuildError(err error) error { + if err == nil { + return nil + } + st, ok := grpcerrors.AsGRPCStatus(err) + if ok { + if st.Code() == codes.Unimplemented && strings.Contains(st.Message(), "unsupported frontend capability moby.buildkit.frontend.contexts") { + return &wrapped{err, "current frontend does not support --build-context. Named contexts are supported since Dockerfile v1.4"} + } + } + return err +} + +type wrapped struct { + err error + msg string +} + +func (w *wrapped) Error() string { + return w.msg +} + +func (w *wrapped) Unwrap() error { + return w.err +} diff --git a/go.mod b/go.mod index c2699bfd..611f3acf 100644 --- a/go.mod +++ b/go.mod @@ -47,6 +47,7 @@ require ( go.opentelemetry.io/otel v1.2.0 go.opentelemetry.io/otel/trace v1.2.0 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c + google.golang.org/grpc v1.42.0 gopkg.in/dancannon/gorethink.v3 v3.0.5 // indirect gopkg.in/fatih/pool.v2 v2.0.0 // indirect gopkg.in/gorethink/gorethink.v3 v3.0.5 // indirect diff --git a/vendor/modules.txt b/vendor/modules.txt index 360b2221..7d0ca6ef 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -564,6 +564,7 @@ google.golang.org/genproto/googleapis/rpc/errdetails google.golang.org/genproto/googleapis/rpc/status google.golang.org/genproto/protobuf/field_mask # google.golang.org/grpc v1.42.0 +## explicit google.golang.org/grpc google.golang.org/grpc/attributes google.golang.org/grpc/backoff