grafana/k6 · error

filepath must not be empty

Error message

filepath must not be empty

What it means

Thrown by fileHook.parseArgs in internal/log/file.go when the k6 log file hook receives a `file=` logging config option with an empty value. The parser accepts the token key but rejects an empty path because no log file could be opened; it fires during k6 startup when parsing the --log-file configuration line via FileHookFromConfigLine.

Source

Thrown at internal/log/file.go:71

		return nil, err
	}
	if err := hook.openFile(getCwd); err != nil {
		return nil, err
	}
	return hook, nil
}

func (h *fileHook) parseArgs(line string) error {
	tokens, err := strvals.Parse(line)
	if err != nil {
		return fmt.Errorf("error while parsing logfile configuration %w", err)
	}

	for _, token := range tokens {
		switch token.Key {
		case "file":
			if token.Value == "" {
				return fmt.Errorf("filepath must not be empty")
			}
			h.path = token.Value
		case "level":
			h.levels, err = parseLevels(token.Value)
			if err != nil {
				return err
			}
		default:
			return fmt.Errorf("unknown logfile config key %s", token.Key)
		}
	}

	return nil
}

// openFile opens logfile and initializes writers.
func (h *fileHook) openFile(getCwd func() (string, error)) error {
	path := h.path

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Provide an actual path after file=, e.g. --log-output=file=./k6.log
  2. Remove the empty file= key if file logging is not intended
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/log/file.go:71 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/fe04a692b43e7a2b. Report an issue: GitHub.