grafana/k6 · error

97

97

Error message

The test has failed

What it means

Returned at the end of `k6 cloud run` when the finished cloud run's result status is 'failed' but thresholds did not cross (that case gets exit 99). k6 exits with code 97 (exitcodes.CloudTestRunFailed), meaning the run itself failed cloud-side or in-script — e.g. script exceptions during execution, an aborted run, or infrastructure errors reported by Grafana Cloud.

Solutions

  1. Open the run details URL printed by k6 — the failure reason is shown in the Grafana Cloud UI
  2. Check the cloud logs pane (or rerun with --show-logs) for script exceptions during the run
  3. If the run was aborted intentionally from the UI, the exit 97 can be ignored
  4. Fix the script errors, verify the archive works locally (`k6 run archive.tar`), then rerun
  5. If Grafana Cloud reports an internal error, retry after the incident resolves

Example fix

// common cause: an exception that only some VUs hit in the cloud
// before
import http from 'k6/http';
export default function () {
  const body = http.get('https://example.com/api').json(); // throws if body isn't JSON
  console.log(body.field.length); // throws if field is undefined
}

// after
import http from 'k6/http';
import check from 'k6/check';
export default function () {
  const res = http.get('https://example.com/api');
  check(res, { 'json body': (r) => r.status === 200 && r.json('field') !== null });
}
Defensive patterns

Strategy: try-catch

Try / catch

k6 cloud run script.js
code=$?
case $code in
  97) echo "cloud run failed - inspect the run URL and cloud logs" ;;
  98) echo "progress monitoring lost" ;;
  99) echo "thresholds crossed" ;;
esac
exit $code

Prevention

When it happens

Trigger: The run finishes with testProgress.TestFailed() true: script errors thrown during iterations in the cloud, the run was aborted from the UI (after the CLI already latched a failed result), or the cloud marked the run failed due to internal errors. Distinct from threshold failures (99) and monitoring loss (98).

Common situations: Unhandled JS exceptions that only trigger under cloud data/distribution; aborting runs from the Grafana UI; cloud-side infrastructure incidents; scripts importing local files/bundled modules that fail in the cloud environment.

Related errors


AI-assisted analysis of grafana/k6@94169daab2 (2026-08-18). Data as JSON: /api/errors/3b6c5cefa3e685fc. Report an issue: GitHub.

Appendix: source

Thrown at internal/cmd/cloud.go:419

	// Stop progress rendering before printing final status to avoid ghost bars.
	progressCancel()
	progressBarWG.Wait()

	if testProgress == nil {
		//nolint:staticcheck
		return errext.WithExitCodeIfNone(errors.New("Test progress error"), exitcodes.CloudFailedToGetProgress)
	}

	printCloudTestStatus(gs, testProgress.FormatStatus())

	if testProgress.ThresholdsFailed() {
		//nolint:staticcheck
		return errext.WithExitCodeIfNone(errors.New("Thresholds have been crossed"), exitcodes.ThresholdsHaveFailed)
	}
	if testProgress.TestFailed() {
		//nolint:staticcheck
		return errext.WithExitCodeIfNone(errors.New("The test has failed"), exitcodes.CloudTestRunFailed)
	}

	return nil
}

func printCloudTestStatus(gs *state.GlobalState, status string) {
	if !gs.Flags.Quiet {
		valueColor := getColor(gs.Flags.NoColor || !gs.Stdout.IsTTY, color.FgCyan)
		printToStdout(gs, fmt.Sprintf(
			"     test status: %s\n", valueColor.Sprint(status),
		))
	} else {
		gs.Logger.WithField("run_status", status).Debug("Test finished")
	}
}

// cloudCmdFlagSet returns the flag set used by the cloud run command,
// binding the --exit-on-running and --show-logs flags to the provided values.

View on GitHub (pinned to 94169daab2)