grafana/k6 · error
reading --features flag: %w
Error message
reading --features flag: %w
What it means
Returned by resolveFeatureFlags when cmd.Flags().GetStringArray("features") errors — i.e. the command has a `features` flag registered but it is not a string-array flag, so the value cannot be read. Like the features.All() failure, this guards an internal invariant of how the flag is declared, not anything the user typed.
Source
Thrown at internal/cmd/features.go:97
out[i] = jsonFlag{
Feature: f.Name,
Lifecycle: f.Lifecycle.String(),
Description: f.Description,
}
}
enc := json.NewEncoder(c.gs.Stdout)
enc.SetIndent("", " ")
return enc.Encode(out)
}
func resolveFeatureFlags(gs *state.GlobalState, cmd *cobra.Command, piState *lib.TestPreInitState) error {
var cli features.Source
if cmd.Flags().Lookup("features") != nil {
cli.Supplied = cmd.Flags().Changed("features")
vals, err := cmd.Flags().GetStringArray("features")
if err != nil {
return fmt.Errorf("reading --features flag: %w", err)
}
cli.Values = vals
}
fileConf, err := readDiskConfig(gs)
if err != nil {
return errext.WithExitCodeIfNone(
fmt.Errorf("failed to load the configuration file from the local file system: %w", err),
exitcodes.InvalidConfig,
)
}
jsonSurface := features.Source{Values: fileConf.Features, Supplied: fileConf.Features != nil}
envSurface := maps.Clone(gs.Env)
if envSurface == nil {
envSurface = make(map[string]string)
}
maps.Copy(envSurface, piState.RuntimeOptions.Env)View on GitHub (pinned to 93accf6570)
Solutions
- If you hit this in a custom build, ensure the flag is registered as an array: `cmd.Flags().StringArrayVar(&v, "features", ...)` before the command runs
- Rebuild against upstream master and retest `k6 run --features experimental-... script.js`
- Report it upstream if reproducible with an unmodified k6 binary
Defensive patterns
Strategy: validation
Validate before calling
# Confirm --features is usable on this binary before pipelines depend on it k6 run --features "$(k6 features -o json 2>/dev/null | jq -r '.[0].name')" --iteration-count 1 - >/dev/null || echo 'features flag unusable on this build'
Prevention
- Upgrade custom forks regularly; this error only exists when flag registration drifts from resolveFeatureFlags
- Use stock binaries in CI for anything exercising --features
When it happens
Trigger: A k6 build/command where `--features` was re-registered with a different type (e.g. plain string) while resolveFeatureFlags still reads it with GetStringArray; occurs during k6 development or in custom forks, never from normal CLI usage.
Common situations: Contributors adding the --features flag to a new subcommand and forgetting Flags().StringArrayVarP; xk6 forks that copied an older flag declaration. For end users the flag is always correctly registered, making this error effectively unreachable.
Related errors
- loading feature definitions: %w
- stack value is required but it was not passed or is empty
- invalid tag, empty name
- invalid tag, empty value
- the --local-execution flag is not compatible with the --exit
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/3848a7393711d002.
Report an issue: GitHub.