grafana/k6 · error

env var '%s' is not a valid boolean value: %w

Error message

env var '%s' is not a valid boolean value: %w

What it means

Boolean-typed K6_* environment variables (K6_INCLUDE_SYSTEM_ENV_VARS, K6_NO_THRESHOLDS, K6_NEW_MACHINE_READABLE_SUMMARY) are read by saveBoolFromEnv and parsed with strconv.ParseBool, which accepts only 1/t/T/TRUE/true/True/0/f/F/FALSE/false/False. Any other word (yes, on, enable) yields "env var 'K6_...' is not a valid boolean value". A valid value is applied only when the corresponding CLI flag was not set explicitly.

Source

Thrown at internal/cmd/runtime_options.go:159

		opts.TracesOutput = null.StringFrom(envVar)
	}

	// If enabled, gather the actual system environment variables
	if opts.IncludeSystemEnvVars.Bool {
		opts.Env = environment
	}

	return opts, nil
}

func saveBoolFromEnv(env map[string]string, varName string, placeholder *null.Bool) error {
	strValue, ok := env[varName]
	if !ok {
		return nil
	}
	val, err := strconv.ParseBool(strValue)
	if err != nil {
		return fmt.Errorf("env var '%s' is not a valid boolean value: %w", varName, err)
	}
	// Only override if not explicitly set via the CLI flag
	if !placeholder.Valid {
		*placeholder = null.BoolFrom(val)
	}
	return nil
}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Set the variable to a ParseBool-accepted literal — 'true' or 'false' is the safe choice
  2. Unset the variable if you did not intend to override the default
  3. Audit the environment for stray K6_* variables: env | grep '^K6_'

Example fix

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

Strategy: validation

Validate before calling

# Accept only strconv.ParseBool literals for K6_* booleans before launching k6
for v in "${K6_INCLUDE_SYSTEM_ENV_VARS-}" "${K6_NO_THRESHOLDS-}" "${K6_NEW_MACHINE_READABLE_SUMMARY-}"; do
  [ -z "$v" ] && continue
  case "$v" in 1|t|T|true|TRUE|True|0|f|F|false|FALSE|False) ;; *) echo "bad boolean: $v" >&2; exit 2;; esac
done

Prevention

When it happens

Trigger: Exporting K6_NO_THRESHOLDS=yes, K6_INCLUDE_SYSTEM_ENV_VARS=on, or K6_NEW_MACHINE_READABLE_SUMMARY=enable before running k6; CI variables defined at organization level with inconsistent boolean spellings.

Common situations: Porting settings from tools where 'yes'/'on' are valid booleans; CI dashboards pre-filling K6_* variables with arbitrary text; shell scripts building K6_* values from unchecked user input.

Related errors


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