Documentation ¶
Overview ¶
Package errext contains extensions for normal Go errors that are used in k6.
Index ¶
- Constants
- func Format(err error) (string, map[string]interface{})
- func IsInterruptError(err error) bool
- func WithAbortReasonIfNone(err error, abortReason AbortReason) error
- func WithExitCodeIfNone(err error, exitCode exitcodes.ExitCode) error
- func WithHint(err error, hint string) error
- type AbortReason
- type Exception
- type HasAbortReason
- type HasExitCode
- type HasHint
- type InterruptError
Constants ¶
const AbortTest = "test aborted"
AbortTest is the reason emitted when a test script calls test.abort()
Variables ¶
This section is empty.
Functions ¶
func Format ¶ added in v0.48.0
Format formats the given error as a message (string) and a map of fields. In case of Exception, it uses the stack trace as the error message. In case of HasHint, it also adds the hint as a field.
func IsInterruptError ¶ added in v0.39.0
IsInterruptError returns true if err is *InterruptError.
func WithAbortReasonIfNone ¶ added in v0.43.0
func WithAbortReasonIfNone(err error, abortReason AbortReason) error
WithAbortReasonIfNone can attach an abort reason to the given error, if it doesn't have one already. It won't do anything if the error already had an abort reason attached. Similarly, if there is no error (i.e. the given error is nil), it also won't do anything and will return nil.
func WithExitCodeIfNone ¶
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.
Types ¶
type AbortReason ¶ added in v0.43.0
type AbortReason uint8
AbortReason is used to signal to outputs what type of error caused the test run to be stopped prematurely.
const ( AbortedByUser AbortReason = iota + 1 AbortedByThreshold AbortedByThresholdsAfterTestEnd // TODO: rename? AbortedByScriptError AbortedByScriptAbort AbortedByTimeout AbortedByOutput )
These are the various reasons why a test might have been aborted prematurely.
type Exception ¶
type Exception interface { error HasAbortReason StackTrace() string }
Exception represents errors that resulted from a script exception and contain a stack trace that lead to them.
type HasAbortReason ¶ added in v0.43.0
type HasAbortReason interface { error AbortReason() AbortReason }
HasAbortReason is a wrapper around an error with an attached abort reason.
type HasExitCode ¶
HasExitCode is a wrapper around an error with an attached exit code.
type HasHint ¶
HasHint is a wrapper around an error with an attached user hint. These hints can be used to give extra human-readable information about the error, including suggestions on how the error can be fixed.
type InterruptError ¶ added in v0.39.0
type InterruptError struct {
Reason string
}
InterruptError is an error that halts engine execution
func (*InterruptError) AbortReason ¶ added in v0.43.0
func (i *InterruptError) AbortReason() AbortReason
AbortReason is used to signal that an InterruptError is caused by the test.abort() functin in k6/execution.
func (*InterruptError) Error ¶ added in v0.39.0
func (i *InterruptError) Error() string
Error returns the reason of the interruption.
func (*InterruptError) ExitCode ¶ added in v0.39.0
func (i *InterruptError) ExitCode() exitcodes.ExitCode
ExitCode returns the status code used when the k6 process exits.