{"record":{"id":"3848a7393711d002","repo":"grafana/k6","slug":"reading-features-flag-w","errorCode":null,"errorMessage":"reading --features flag: %w","messagePattern":"reading --features flag: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/features.go","lineNumber":97,"sourceCode":"\t\tout[i] = jsonFlag{\n\t\t\tFeature:     f.Name,\n\t\t\tLifecycle:   f.Lifecycle.String(),\n\t\t\tDescription: f.Description,\n\t\t}\n\t}\n\n\tenc := json.NewEncoder(c.gs.Stdout)\n\tenc.SetIndent(\"\", \"  \")\n\treturn enc.Encode(out)\n}\n\nfunc resolveFeatureFlags(gs *state.GlobalState, cmd *cobra.Command, piState *lib.TestPreInitState) error {\n\tvar cli features.Source\n\tif cmd.Flags().Lookup(\"features\") != nil {\n\t\tcli.Supplied = cmd.Flags().Changed(\"features\")\n\t\tvals, err := cmd.Flags().GetStringArray(\"features\")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"reading --features flag: %w\", err)\n\t\t}\n\t\tcli.Values = vals\n\t}\n\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)","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cmd/features.go#L79-L115","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Confirm --features is usable on this binary before pipelines depend on it\nk6 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'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Upgrade custom forks regularly; this error only exists when flag registration drifts from resolveFeatureFlags","Use stock binaries in CI for anything exercising --features"],"tags":["feature-flags","cli","flags","internal"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}