grafana/k6 · error

reading --features flag

Error message

reading --features flag: %w

What it means

Wrapped error from resolveFeatureFlags: reading the --features CLI flag values via pflag failed. This should not happen in normal operation — it indicates an internal flag-registration inconsistency rather than bad user input.

Solutions

  1. Retry with a correctly formatted --features FlagName[=value] argument
  2. Report as an internal bug if the flag syntax is valid but the error persists
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/cmd/features.go:97 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/3848a7393711d002. Report an issue: GitHub.

Appendix: 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 01ffac6f24)