jaegertracing/jaeger · error

cannot parse UI config file %v: %w

Error message

cannot parse UI config file %v: %w

What it means

The UI config file was read successfully but is not valid JSON: json.Unmarshal into map[string]any failed. Jaeger re-marshals the parsed map to produce the JAEGER_CONFIG blob injected into index.html, so the file must be strict JSON when it has a .json extension.

Source

Thrown at cmd/jaeger/internal/extension/jaegerquery/internal/static_handler.go:224

}

func loadUIConfig(uiConfig string) (*loadedConfig, error) {
	if uiConfig == "" {
		return nil, nil
	}
	bytesConfig, err := os.ReadFile(filepath.Clean(uiConfig))
	if err != nil {
		return nil, fmt.Errorf("cannot read UI config file %v: %w", uiConfig, err)
	}
	var r []byte

	ext := filepath.Ext(uiConfig)
	switch strings.ToLower(ext) {
	case ".json":
		var c map[string]any

		if err := json.Unmarshal(bytesConfig, &c); err != nil {
			return nil, fmt.Errorf("cannot parse UI config file %v: %w", uiConfig, err)
		}
		r, _ = json.Marshal(c)

		return &loadedConfig{
			regexp: configPattern,
			config: append([]byte("JAEGER_CONFIG = "), append(r, byte(';'))...),
		}, nil
	case ".js":
		r = bytes.TrimSpace(bytesConfig)
		re := regexp.MustCompile(`function\s+UIConfig(\s)?\(\s?\)(\s)?{`)
		if !re.Match(r) {
			return nil, fmt.Errorf("UI config file must define function UIConfig(): %v", uiConfig)
		}

		return &loadedConfig{
			regexp: configJsPattern,
			config: r,
		}, nil

View on GitHub (pinned to 806f444784)

Solutions

  1. Validate the file with a JSON linter (jq . ui-config.json) and fix the syntax error reported by the wrapped error.
  2. Remove comments, trailing commas, and BOM — strict JSON only.
  3. If the file is actually JavaScript, rename it to .js so it takes the JS parsing branch instead.
  4. Regenerate the config from your UI config tooling rather than hand-editing.

Example fix

// before (ui-config.json)
{ "menu": [ { "label": "Docs", "url": "https://jaeger.dev", }, ] }
// after
{ "menu": [ { "label": "Docs", "url": "https://jaeger.dev" } ] }
Defensive patterns

Strategy: validation

Validate before calling

var probe map[string]any
if err := json.NewDecoder(bytes.NewReader(bytesConfig)).Decode(&probe); err != nil {
    return fmt.Errorf("ui config %s is not valid JSON: %w", path, err)
}

Try / catch

if err := json.Unmarshal(data, &c); err != nil {
    var syn *json.SyntaxError
    if errors.As(err, &syn) {
        log.Printf("JSON syntax at offset %d: %v", syn.Offset, syn.Error())
    }
    return err
}

Prevention

When it happens

Trigger: loadUIConfig with a file whose extension is .json (case-insensitive) where json.Unmarshal(bytesConfig, &c) returns an error — malformed JSON, trailing commas, comments, duplicate keys of wrong type, or BOM/HTML content saved as .json.

Common situations: Hand-edited JSON with a trailing comma or single quotes; a config file copied from docs containing /* comments */; saving a .js UI config with a .json extension; editor adding a UTF-8 BOM.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of jaegertracing/jaeger@806f444784 (2026-09-01). Data as JSON: /api/errors/9327adf0e64d96dd. Report an issue: GitHub.