grafana/k6 · error
env var ' ' is not a valid boolean value
Error message
env var '%s' is not a valid boolean value: %w
What it means
Boolean runtime options can be set from the environment; saveBoolFromEnv parses K6_INCLUDE_SYSTEM_ENV_VARS and K6_NO_THRESHOLDS with strconv.ParseBool. Only 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False are accepted — anything else ('yes', 'on', 'enable') aborts startup with this error naming the offending variable. An explicitly set CLI flag is not overridden by the env value.
Solutions
- Use an accepted boolean literal: K6_NO_THRESHOLDS=true (or 1/0)
- Unset the variable if you don't need the option
- Fix the definition in the env file / CI settings that injected the bad value
Example fix
# before K6_NO_THRESHOLDS=yes k6 run script.js # after K6_NO_THRESHOLDS=true k6 run script.js
Defensive patterns
Strategy: validation
Validate before calling
# preflight boolean env vars accepted by Go's ParseBool
check_bool_env() {
v="${!1:-}"
[ -z "$v" ] && return 0
case "${v,,}" in
1|t|true|0|f|false) return 0;;
*) echo "$1=$v is not a valid boolean (use true/false/1/0)" >&2; return 1;;
esac
}
check_bool_env K6_NO_THRESHOLDS && check_bool_env K6_INCLUDE_SYSTEM_ENV_VARS || exit 1
k6 run script.js Prevention
- Use only true/false/1/0 for K6 boolean env vars — 'yes' and 'on' are rejected
- Standardize one boolean convention across the CI env files for all tools
- Only K6_INCLUDE_SYSTEM_ENV_VARS and K6_NO_THRESHOLDS flow through this check — keep their definitions in reviewed config
When it happens
Trigger: K6_NO_THRESHOLDS=yes k6 run script.js; K6_INCLUDE_SYSTEM_ENV_VARS=on; docker-compose env files or CI variables using yes/no conventions.
Common situations: Porting configuration from tools that accept yes/no or on/off; hand-edited .env files; variable reused across tools with different boolean syntaxes.
Understand the failure class
Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.
Related errors
- failed to initialize cloud secret source
- invalid environment variable name
- a function is expected as the second argument of…
- both K6_CLOUD_METRICS_PUSH_URL and K6_CLOUD_TEST_RUN_TOKEN…
- can't have two secret sources that are default ones, second…
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/c7a9e452839f09e3.
Report an issue: GitHub.
Appendix: 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 01ffac6f24)