{"record":{"id":"e91d5dbfc2a2379d","repo":"grafana/k6","slug":"failed-to-load-the-configuration-file-from-the-loc","errorCode":null,"errorMessage":"failed to load the configuration file from the local file system: %w","messagePattern":"failed to load the configuration file from the local file system: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/config.go","lineNumber":221,"sourceCode":"\t})\n\treturn conf, err\n}\n\n// getConsolidatedConfig assemble the final consolidated configuration from all of the different sources:\n// - start with the CLI-provided options to get shadowed (non-Valid) defaults in there\n// - add the global file config options\n// - add the Runner-provided options (they may come from Bundle too if applicable)\n// - add the environment variables\n// - merge the user-supplied CLI flags back in on top, to give them the greatest priority\n// - set some defaults if they weren't previously specified\n// TODO: add better validation, more explicit default values and improve consistency between formats\n// TODO: accumulate all errors and differentiate between the layers?\nfunc getConsolidatedConfig(\n\tgs *state.GlobalState, cliConf Config, runnerOpts lib.Options, flags *features.Flags,\n) (Config, error) {\n\tfileConf, err := readDiskConfig(gs)\n\tif err != nil {\n\t\terr = fmt.Errorf(\"failed to load the configuration file from the local file system: %w\", err)\n\t\treturn Config{}, errext.WithExitCodeIfNone(err, exitcodes.InvalidConfig)\n\t}\n\n\tenvConf, err := readEnvConfig(gs.Env)\n\tif err != nil {\n\t\treturn Config{}, errext.WithExitCodeIfNone(err, exitcodes.InvalidConfig)\n\t}\n\n\tconf := cliConf.Apply(fileConf)\n\n\twarnOnShortHandOverride(conf.Options, runnerOpts, \"script\", gs.Logger)\n\tconf = conf.Apply(Config{Options: runnerOpts})\n\n\twarnOnShortHandOverride(conf.Options, envConf.Options, \"env\", gs.Logger)\n\tconf = conf.Apply(envConf)\n\n\twarnOnShortHandOverride(conf.Options, cliConf.Options, \"cli\", gs.Logger)\n\tconf = conf.Apply(cliConf)","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cmd/config.go#L203-L239","documentation":"Top-level wrapper produced by getConsolidatedConfig, the function that merges all configuration layers (CLI > env > runner options > file config). It fires when readDiskConfig fails and attaches exit code InvalidConfig (104), so besides the message the k6 process exits with a specific code. The underlying error is one of the two readDiskConfig failures: unreadable file (I/O) or unparseable JSON.","triggerScenarios":"Any command that consolidates config (k6 run, k6 cloud run, k6 archive, ...) while the config file from --config/K6_CONFIG/default path is either unreadable (permissions, directory, dangling symlink) or contains invalid JSON.","commonSituations":"Same real-world causes as the readDiskConfig errors: permission changes, malformed hand-edits, CI-baked broken configs. Users see it as the outermost message, so the fix requires reading the wrapped inner error naming the file and JSON offset.","solutions":["Read the wrapped (inner) error in the output — it is either \"couldn't load the configuration from %q\" (I/O) or \"couldn't parse the configuration from %q\" (JSON) and names the exact file","For I/O failures: fix permissions/ownership so the current user can read the file","For parse failures: validate with `jq . <file>` and fix the JSON syntax at the reported offset","Temporary workaround: run with an explicit empty config `--config /dev/null` (or unset K6_CONFIG) to confirm the rest of the setup is fine"],"exampleFix":"# before\n$ k6 run script.js\n# error: failed to load the configuration file from the local file system: couldn't parse the configuration from \"k6.json\": invalid character '}' looking for beginning of value\n\n# after\n$ jq . k6.json   # locate & fix syntax, then re-run\n$ k6 run script.js","handlingStrategy":"validation","validationCode":"# Pre-flight the whole config surface: readable + valid JSON\nk6 inspect -o execution-script script.js >/dev/null 2>cfg.err || true\ngrep -q 'failed to load the configuration file' cfg.err && { echo 'fix k6 config first'; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat the k6 config file like code: lint it in CI when it changes","Watch exit code 104 (InvalidConfig) in pipelines as the signal of config-layer failures","Keep --config explicit in automation so the default-path fallback can't mask which file is in play"],"tags":["config","exit-code","json","filesystem"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}