MCPcopy
hub / github.com/grafana/k6 / WithExitCodeIfNone

Function WithExitCodeIfNone

errext/exit_code.go:23–34  ·  view source on GitHub ↗

WithExitCodeIfNone can attach an exit code to the given error, if it doesn't have one already. It won't do anything if the error already had an exit code attached. Similarly, if there is no error (i.e. the given error is nil), it also won't do anything.

(err error, exitCode exitcodes.ExitCode)

Source from the content-addressed store, hash-verified

21// attached. Similarly, if there is no error (i.e. the given error is nil), it
22// also won't do anything.
23func WithExitCodeIfNone(err error, exitCode exitcodes.ExitCode) error {
24 if err == nil {
25 // No error, do nothing
26 return nil
27 }
28 var ecerr HasExitCode
29 if errors.As(err, &ecerr) {
30 // The given error already has an exit code, do nothing
31 return err
32 }
33 return withExitCodeError{err, exitCode}
34}
35
36type withExitCodeError struct {
37 error

Callers 15

ValidateMethod · 0.92
handleFlushErrorMethod · 0.92
GetConsolidatedConfigFunction · 0.92
populateExportsMethod · 0.92
prepareFirstRunnerMethod · 0.92
resolveFeatureFlagsFunction · 0.92
preRunMethod · 0.92
runMethod · 0.92
runMethod · 0.92
persistentPreRunEMethod · 0.92

Calls

no outgoing calls

Tested by 1

TestErrextHelpersFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…