grafana/k6 · error

failed to load the configuration file from the local file sy

Error message

failed to load the configuration file from the local file system: %w

What it means

Emitted by resolveFeatureFlags (the shared pre-init path for feature flags) when readDiskConfig fails while resolving the JSON-config surface for features. It wraps the same readDiskConfig errors as getConsolidatedConfig does — unreadable file (I/O) or invalid JSON — and attaches exit code InvalidConfig.

Source

Thrown at internal/cmd/features.go:105

	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)

	flags, err := features.Init(gs.Logger, cli, jsonSurface, envSurface)
	if err != nil {
		return fmt.Errorf("initializing feature flags: %w", err)
	}
	piState.FeatureFlags = flags

	for _, name := range flags.Activated() {

View on GitHub (pinned to 93accf6570)

Solutions

  1. Read the inner wrapped error — it names the config path and whether the failure is I/O ("couldn't load") or JSON ("couldn't parse")
  2. Fix permissions for I/O failures; fix JSON syntax with `jq . <path>` for parse failures
  3. Pass feature flags via CLI/env only and point --config at a known-good file to confirm the config is the culprit
  4. Or remove/repair the config file so the default path is either valid JSON or absent (absent default is silently ignored)

Example fix

# before
$ k6 run script.js --log-output=stdout
# error: failed to load the configuration file from the local file system: couldn't parse ...

# after
$ jq . ~/.config/loadimpact/k6.json  # fix reported syntax error, then
$ k6 run script.js
Defensive patterns

Strategy: validation

Validate before calling

# Validate config JSON ahead of any feature-flag-driven run
cfg="${K6_CONFIG:-$HOME/.config/loadimpact/k6.json}"
[ ! -f "$cfg" ] || jq -e . "$cfg" >/dev/null || { echo "fix $cfg"; exit 1; }

Prevention

When it happens

Trigger: Running a command that pre-resolves feature flags with a --config/K6_CONFIG/default config file that exists but cannot be read or does not parse as JSON; the features-specific surfaces (CLI --features, K6_FEATURES-style env, runtime env) are merged only after this read succeeds.

Common situations: Same root causes as the other config errors: hand-edited k6.json with a trailing comma, permission-restricted config, or a CI-baked broken file — surfacing here even before script loading because feature flags are resolved in the test's pre-init state.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/48dc2fac264413c9. Report an issue: GitHub.