{"record":{"id":"c9d0d30d6b149058","repo":"grafana/k6","slug":"initializing-feature-flags-w","errorCode":null,"errorMessage":"initializing feature flags: %w","messagePattern":"initializing feature flags: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/features.go","lineNumber":119,"sourceCode":"\n\tfileConf, err := readDiskConfig(gs)\n\tif err != nil {\n\t\treturn errext.WithExitCodeIfNone(\n\t\t\tfmt.Errorf(\"failed to load the configuration file from the local file system: %w\", err),\n\t\t\texitcodes.InvalidConfig,\n\t\t)\n\t}\n\tjsonSurface := features.Source{Values: fileConf.Features, Supplied: fileConf.Features != nil}\n\n\tenvSurface := maps.Clone(gs.Env)\n\tif envSurface == nil {\n\t\tenvSurface = make(map[string]string)\n\t}\n\tmaps.Copy(envSurface, piState.RuntimeOptions.Env)\n\n\tflags, err := features.Init(gs.Logger, cli, jsonSurface, envSurface)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"initializing feature flags: %w\", err)\n\t}\n\tpiState.FeatureFlags = flags\n\n\tfor _, name := range flags.Activated() {\n\t\tif err := gs.Usage.Strings(\"features\", name); err != nil {\n\t\t\tgs.Logger.WithError(err).Debugf(\"reporting feature usage for %q\", name)\n\t\t}\n\t}\n\n\tpropagateFeatureEnv(piState.RuntimeOptions.Env, flags.Activated())\n\treturn nil\n}\n\nfunc warnOnScriptOptionsFeatures(logger logrus.FieldLogger, opts lib.Options) {\n\tif len(opts.Features) == 0 {\n\t\treturn\n\t}\n\tlogger.WithField(\"source\", \"options\").","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cmd/features.go#L101-L137","documentation":"Emitted by resolveFeatureFlags when features.Init fails to reconcile the three feature-flag surfaces: CLI --features, the JSON config `features` key, and environment variables (K6_* runtime env). Init resolves each supplied name against the registered feature-flag definitions (and their aliases) and errors on unknown flag names or values that cannot be applied to the flag fields.","triggerScenarios":"Passing a misspelled or unregistered flag: `k6 run --features expermental-native-histograms script.js`; a `features: [\"nope\"]` array in the config file; K6_FEATURES-style env vars with names that match no declared flag/alias; values that are not valid booleans for a flag.","commonSituations":"Feature flags renamed/removed between k6 versions (scripts or CI env carrying old experimental names); typos in pipelines; copying flag lists from docs for a different k6 version. The registered flags in this build are visible via `k6 features`.","solutions":["Run `k6 features` to list every valid flag name and lifecycle for your exact binary","Correct the offending surface: fix the name in --features, the config file `features` array, or the env var","Remove flags that no longer exist in your k6 version instead of keeping them 'just in case'","Pin/align the k6 version in CI so documented flag names match the binary in use"],"exampleFix":"# before\n$ k6 run --features expermental-native-histograms script.js\n# error: initializing feature flags: ...\n\n# after\n$ k6 features   # confirm the exact name\n$ k6 run --features experimental-native-histograms script.js","handlingStrategy":"validation","validationCode":"# Only pass flags your binary actually knows\nfor f in $(k6 features -o json | jq -r '.[].name'); do echo \"ok:$f\"; done\n# then diff your --features / K6_FEATURES values against that list before running","typeGuard":null,"tryCatchPattern":null,"preventionTips":["List valid flags with `k6 features` after every k6 upgrade","Centralize feature-flag values in one CI variable instead of scattering them across env/config/CLI","Delete rather than comment out stale experimental flag names"],"tags":["feature-flags","config","env","validation"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}