grafana/k6 · error

parsing K6_SHOW_CLOUD_LOGS returned an error: %w

Error message

parsing K6_SHOW_CLOUD_LOGS returned an error: %w

What it means

The `k6 cloud` preRun hook parses K6_SHOW_CLOUD_LOGS with strconv.ParseBool and fails. ParseBool only accepts 1, t, T, true, TRUE, True, 0, f, F, false, FALSE, False; anything else (yes, on, enable, 'true ' with whitespace) is rejected. The check runs even when the --show-logs flag would override the env var, so an invalid value always aborts the command.

Source

Thrown at internal/cmd/cloud.go:136

// cmdCloud handles the `k6 cloud` sub-command
type cmdCloud struct {
	gs *state.GlobalState

	showCloudLogs bool
	exitOnRunning bool
	uploadOnly    bool
}

func (c *cmdCloud) preRun(cmd *cobra.Command, _ []string) error {
	// 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
}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Set the variable to a strict Go boolean literal: K6_SHOW_CLOUD_LOGS=true or =false
  2. Unset the variable if you do not need it
  3. Use the --show-logs / --no-show-logs CLI flag instead, but note the env var must still parse if present

Example fix

# before
export K6_SHOW_CLOUD_LOGS=yes
# after
export K6_SHOW_CLOUD_LOGS=true
Defensive patterns

Strategy: validation

Validate before calling

if v, ok := os.LookupEnv("K6_SHOW_CLOUD_LOGS"); ok {
    if _, err := strconv.ParseBool(v); err != nil {
        log.Fatalf("K6_SHOW_CLOUD_LOGS=%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_SHOW_CLOUD_LOGS is exported with a value outside ParseBool's accepted set, e.g. 'yes', 'on', or one containing trailing whitespace or a newline.

Common situations: CI systems templating boolean-looking strings ('True' with quotes included, 'yes'); Docker ENV values copied from YAML where quoting mangles the value; sharing shell profiles between tools with different boolean conventions.

Related errors


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