Skip to content

Commit f7a1572

Browse files
authored
fix: engine.Close() ordering (#1631)
1 parent e766ccf commit f7a1572

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

external/run/run.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ func DefaultLanguages() []Language {
8888

8989
func Run(version, commitSHA string, engine Engine) {
9090
err := commands.NewApp(version, commitSHA, engine).Execute()
91-
engine.Close()
9291

9392
if err != nil {
9493
// error messages are printed by the framework

pkg/commands/artifact/run.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ func getIgnoredFingerprints(settings settings.Config) (
240240
return false, localIgnoredFingerprints, []string{}, nil
241241
}
242242

243+
244+
type ReportFailedError int
245+
func (exitcode ReportFailedError) Error() string {
246+
return "Report failed with exitcode"
247+
}
248+
243249
// Run performs artifact scanning
244250
func Run(ctx context.Context, opts flagtypes.Options, engine engine.Engine) (err error) {
245251
targetPath, err := file.CanonicalPath(opts.Target)
@@ -341,9 +347,9 @@ func Run(ctx context.Context, opts flagtypes.Options, engine engine.Engine) (err
341347

342348
if reportFailed {
343349
if scanSettings.Scan.ExitCode == -1 {
344-
defer os.Exit(1)
350+
return ReportFailedError(1)
345351
} else {
346-
defer os.Exit(scanSettings.Scan.ExitCode)
352+
return ReportFailedError(scanSettings.Scan.ExitCode)
347353
}
348354
}
349355

pkg/commands/scan.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package commands
22

33
import (
44
"fmt"
5+
"os"
56

67
"github.com/bearer/bearer/pkg/commands/artifact"
78
"github.com/bearer/bearer/pkg/commands/debugprofile"
@@ -87,6 +88,12 @@ func NewScanCommand(engine engine.Engine) *cobra.Command {
8788

8889
err = artifact.Run(cmd.Context(), options, engine)
8990
debugprofile.Stop()
91+
engine.Close()
92+
93+
if exitcode, ok := err.(artifact.ReportFailedError); ok {
94+
os.Exit(int(exitcode))
95+
}
96+
9097
return err
9198
},
9299
SilenceErrors: false,

0 commit comments

Comments
 (0)