grafana/k6 · error

failed to parse JSON config: %w

Error message

failed to parse JSON config: %w

What it means

The config file contents are unmarshaled into extConfig with encoding/json; a syntax error, wrong types, or non-JSON content produces this wrapped error. The file exists but is not a valid JSON config for the url secret source.

Source

Thrown at internal/secretsource/url/url.go:512

	return cfg, nil
}

func loadConfigFromFile(configPath string, fs fsext.Fs) (extConfig, error) {
	file, err := fs.Open(configPath)
	if err != nil {
		return extConfig{}, fmt.Errorf("failed to open config file: %w", err)
	}
	defer func() { _ = file.Close() }()

	configData, err := io.ReadAll(file)
	if err != nil {
		return extConfig{}, fmt.Errorf("failed to read config file: %w", err)
	}

	var fileCfg extConfig
	if err := json.Unmarshal(configData, &fileCfg); err != nil {
		return extConfig{}, fmt.Errorf("failed to parse JSON config: %w", err)
	}

	return fileCfg, nil
}

func validateURLTemplate(urlTemplate string) error {
	if urlTemplate == "" {
		return errMissingURLTemplate
	}

	// Require {key} placeholder to differentiate between secrets
	if !strings.Contains(urlTemplate, "{key}") {
		return errors.New("urlTemplate must contain {key} placeholder")
	}

	// Replace {key} placeholder with a dummy value for validation
	testURL := strings.ReplaceAll(urlTemplate, "{key}", "test")
	parsedURL, err := url.Parse(testURL)

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Validate the JSON syntax of the config file
  2. Match the expected field names and types (strings, numbers, durations as strings)
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/secretsource/url/url.go:512 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/2758acd89b8374d9. Report an issue: GitHub.