{"record":{"id":"6464a16f36f79e82","repo":"grafana/k6","slug":"110","errorCode":"110","errorMessage":"test run was marked as failed","messagePattern":"test run was marked as failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/run.go","lineNumber":487,"sourceCode":"\t// Check what the execScheduler.Run() error is.\n\tif err != nil {\n\t\terr = common.UnwrapSobekInterruptedError(err)\n\t\tlogger.WithError(err).Debug(\"Test finished with an error\")\n\t\treturn err\n\t}\n\n\t// Warn if no iterations could be completed.\n\tif executionState.GetFullIterationCount() == 0 {\n\t\tlogger.Warn(\"No script iterations fully finished, consider making the test duration longer\")\n\t}\n\n\t// The execution module enables users to mark a test as failed, while letting the test\n\t// execution complete. As such, we check the test status here, after the test run has finished, and\n\t// ensure we return an error indicating that the test run was marked as failed, and the proper\n\t// exit code is used.\n\tif testRunState.TestStatus.Failed() {\n\t\treturn errext.WithExitCodeIfNone(\n\t\t\tfmt.Errorf(\"test run was marked as failed\"),\n\t\t\texitcodes.MarkedAsFailed,\n\t\t)\n\t}\n\n\tlogger.Debug(\"Test finished cleanly\")\n\n\treturn nil\n}\n\nfunc getSummaryMode(runtimeOptions lib.RuntimeOptions) (summary.Mode, bool, error) {\n\tsm, err := summary.ValidateMode(runtimeOptions.SummaryMode.String)\n\tif err != nil {\n\t\treturn summary.ModeDisabled, false, err\n\t}\n\n\treturn sm, sm != summary.ModeDisabled, nil\n}\n","sourceCodeStart":469,"sourceCodeEnd":505,"githubUrl":"https://github.com/grafana/k6/blob/94169daab29df52c1ed2ee0549657a577666b855/internal/cmd/run.go#L469-L505","documentation":"execution.test.fail(msg) (k6/execution, also surfaced via the experimental test module) marks the whole test as failed while letting the run finish — unlike test.abort(), which interrupts it. After execution completes, run() checks TestStatus.Failed() and returns this error with exit code 110 (MarkedAsFailed). The reason string passed to fail() is also logged at ERROR level during the run, which is the fastest way to find the call site.","triggerScenarios":"Calling execution.test.fail('login endpoint returned 5xx') anywhere in VU code when an application-level condition is detected; the run then completes all iterations and exits 110 instead of 0.","commonSituations":"Business-assertion scripts that must fail the run on content errors (wrong JSON, missing field) that HTTP metrics and thresholds don't capture; smoke tests asserting critical flows.","solutions":["Search the script for 'test.fail' and read the matching ERROR log line — it contains the reason string you passed","Fix the condition that triggered the failure (usually a real application error the script correctly detected)","If the condition should not be fatal, downgrade to check() or console.error instead of test.fail()","In CI, map exit code 110 to 'script-asserted failure', distinct from 99 (thresholds) and 105 (aborted)"],"exampleFix":"// before\nimport execution from 'k6/execution';\nif (res.status >= 500) execution.test.fail('got 5xx');\n\n// after (non-fatal assertion)\nimport { check } from 'k6';\ncheck(res, { 'status is 2xx': (r) => r.status >= 200 && r.status < 300 });","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"# map exit 110 to a script-assertion failure bucket\nk6 run script.js\nec=$?\ncase $ec in\n  110) echo \"script called execution.test.fail() — see ERROR lines in the log for the reason\"; exit 110;;\n  *)   exit $ec;;\nesac","preventionTips":["Use execution.test.fail() only for conditions that must fail the run; use check() for non-fatal assertions","Always pass a descriptive reason string — it appears in the ERROR log and is your only call-site breadcrumb","Search scripts for 'test.fail' when exit code 110 appears; the log line 'test was marked as failed: <reason>' pinpoints it","Keep the k6/execution import at the top so grep finds all fail/abort call sites quickly"],"tags":["k6","execution","test-fail","exit-code-110","script"],"backgroundTag":"explicit-test-failure","analyzedSha":"94169daab29df52c1ed2ee0549657a577666b855","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}