Merge pull request #3278 from crazy-max/fix-exit-after-defer
cmd: fix possible skipped defers for build and bake
This commit is contained in:
@@ -49,7 +49,6 @@ linters:
|
||||
- "assignOp"
|
||||
- "appendAssign"
|
||||
- "singleCaseSwitch"
|
||||
- "exitAfterDefer" # FIXME
|
||||
gosec:
|
||||
excludes:
|
||||
- G204
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/docker/buildx/commands"
|
||||
"github.com/docker/buildx/util/cobrautil"
|
||||
"github.com/docker/buildx/util/desktop"
|
||||
"github.com/docker/buildx/version"
|
||||
"github.com/docker/cli/cli"
|
||||
@@ -101,6 +102,13 @@ func main() {
|
||||
os.Exit(sterr.StatusCode)
|
||||
}
|
||||
|
||||
// Check for ExitCodeError, which is used to exit with a specific code
|
||||
// without printing an error message.
|
||||
var exitCodeErr cobrautil.ExitCodeError
|
||||
if errors.As(err, &exitCodeErr) {
|
||||
os.Exit(int(exitCodeErr))
|
||||
}
|
||||
|
||||
for _, s := range solvererrdefs.Sources(err) {
|
||||
s.Print(cmd.Err())
|
||||
}
|
||||
|
||||
+2
-1
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/docker/buildx/builder"
|
||||
"github.com/docker/buildx/localstate"
|
||||
"github.com/docker/buildx/util/buildflags"
|
||||
"github.com/docker/buildx/util/cobrautil"
|
||||
"github.com/docker/buildx/util/cobrautil/completion"
|
||||
"github.com/docker/buildx/util/confutil"
|
||||
"github.com/docker/buildx/util/desktop"
|
||||
@@ -448,7 +449,7 @@ func runBake(ctx context.Context, dockerCli command.Cli, targets []string, in ba
|
||||
}
|
||||
|
||||
if exitCode != 0 {
|
||||
os.Exit(exitCode)
|
||||
return cobrautil.ExitCodeError(exitCode)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
+3
-3
@@ -384,10 +384,10 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
|
||||
}
|
||||
}
|
||||
if opts.CallFunc != nil {
|
||||
if exitcode, err := printResult(dockerCli.Out(), opts.CallFunc, resp.ExporterResponse, options.target, inputs); err != nil {
|
||||
if exitCode, err := printResult(dockerCli.Out(), opts.CallFunc, resp.ExporterResponse, options.target, inputs); err != nil {
|
||||
return err
|
||||
} else if exitcode != 0 {
|
||||
os.Exit(exitcode)
|
||||
} else if exitCode != 0 {
|
||||
return cobrautil.ExitCodeError(exitCode)
|
||||
}
|
||||
}
|
||||
if v, ok := resp.ExporterResponse["frontend.result.inlinemessage"]; ok {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package cobrautil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ExitCodeError int
|
||||
|
||||
func (e ExitCodeError) Error() string {
|
||||
return fmt.Sprintf("exiting with code %d", int(e))
|
||||
}
|
||||
|
||||
func (e ExitCodeError) Unwrap() error {
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user