grafana/k6 · error

parsing K6_EXIT_ON_RUNNING returned an error: %w

Error message

parsing K6_EXIT_ON_RUNNING returned an error: %w

What it means

The `k6 cloud` preRun hook parses K6_EXIT_ON_RUNNING with strconv.ParseBool and fails. As with K6_SHOW_CLOUD_LOGS, only Go-style boolean literals (1/t/true/0/f/false in any capitalization ParseBool accepts) are valid. The value is validated even when --exit-on-running overrides it, so a bad value always stops the command.

Source

Thrown at internal/cmd/cloud.go:146

	// TODO: refactor (https://github.com/grafana/k6/issues/883)
	//
	// We deliberately parse the env variables, to validate for wrong
	// values, even if we don't subsequently use them (if the respective
	// CLI flag was specified, since it has a higher priority).
	if showCloudLogsEnv, ok := c.gs.Env["K6_SHOW_CLOUD_LOGS"]; ok {
		showCloudLogsValue, err := strconv.ParseBool(showCloudLogsEnv)
		if err != nil {
			return fmt.Errorf("parsing K6_SHOW_CLOUD_LOGS returned an error: %w", err)
		}
		if !cmd.Flags().Changed("show-logs") {
			c.showCloudLogs = showCloudLogsValue
		}
	}

	if exitOnRunningEnv, ok := c.gs.Env["K6_EXIT_ON_RUNNING"]; ok {
		exitOnRunningValue, err := strconv.ParseBool(exitOnRunningEnv)
		if err != nil {
			return fmt.Errorf("parsing K6_EXIT_ON_RUNNING returned an error: %w", err)
		}
		if !cmd.Flags().Changed("exit-on-running") {
			c.exitOnRunning = exitOnRunningValue
		}
	}
	return nil
}

// TODO: split apart some more
//
//nolint:funlen,gocognit,cyclop
func (c *cmdCloud) run(cmd *cobra.Command, args []string) error {
	test, err := loadAndConfigureLocalTest(c.gs, cmd, args, getPartialConfig)
	if err != nil {
		return err
	}

	// It's important to NOT set the derived options back to the runner

View on GitHub (pinned to 93accf6570)

Solutions

  1. Set K6_EXIT_ON_RUNNING to true or false exactly
  2. Unset the variable if unused
  3. Prefer the --exit-on-running flag, while ensuring any env var present still parses

Example fix

# before
export K6_EXIT_ON_RUNNING=on
# after
export K6_EXIT_ON_RUNNING=true
Defensive patterns

Strategy: validation

Validate before calling

if v, ok := os.LookupEnv("K6_EXIT_ON_RUNNING"); ok {
    if _, err := strconv.ParseBool(v); err != nil {
        log.Fatalf("K6_EXIT_ON_RUNNING=%q is not a valid bool (use true/false)", v)
    }
}

Type guard

func isValidK6Bool(v string) bool {
    _, err := strconv.ParseBool(v)
    return err == nil
}

Prevention

When it happens

Trigger: K6_EXIT_ON_RUNNING is set to something like 'yes', 'on', '1 ' (trailing space), or 'TRUE\'', which strconv.ParseBool rejects.

Common situations: Templates or CI variables that emit non-literal booleans; copy-pasted env blocks from tutorials using 'on'; secrets managers injecting values with surrounding whitespace.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/bc425dd4619eb5c3. Report an issue: GitHub.