wavetermdev/waveterm · error

json syntax error at line %d, col %d: probably an extra trai

Error message

json syntax error at line %d, col %d: probably an extra trailing comma: %v

What it means

This is the trailing-comma variant of the JSON syntax error produced while parsing Wave configuration files. When a json.SyntaxError occurs and isTrailingCommaError detects the offending offset points at a trailing comma, the error is wrapped with a 'probably an extra trailing comma' hint plus line/column. It is collected into ConfigError entries and returned by the Generate* meta-constant functions.

Source

Thrown at pkg/wconfig/settingsconfig.go:538

	var cerrs []ConfigError
	if readErr != nil && !os.IsNotExist(readErr) {
		cerrs = append(cerrs, ConfigError{File: fileName, Err: readErr.Error()})
	}
	if len(barr) == 0 {
		return nil, cerrs
	}
	var rtn waveobj.MetaMapType
	err := json.Unmarshal(barr, &rtn)
	if err != nil {
		if syntaxErr, ok := err.(*json.SyntaxError); ok {
			offset := syntaxErr.Offset
			if offset > 0 {
				offset = offset - 1
			}
			lineNum, colNum := utilfn.GetLineColFromOffset(barr, int(offset))
			isTrailingComma := isTrailingCommaError(barr, int(offset))
			if isTrailingComma {
				err = fmt.Errorf("json syntax error at line %d, col %d: probably an extra trailing comma: %v", lineNum, colNum, syntaxErr)
			} else {
				err = fmt.Errorf("json syntax error at line %d, col %d: %v", lineNum, colNum, syntaxErr)
			}
		}
		cerrs = append(cerrs, ConfigError{File: fileName, Err: err.Error()})
	}

	// Resolve environment variable replacements
	if rtn != nil {
		resolveEnvReplacements(rtn)
	}

	return rtn, cerrs
}

func readConfigFileFS(fsys fs.FS, logPrefix string, fileName string) (waveobj.MetaMapType, []ConfigError) {
	barr, readErr := fs.ReadFile(fsys, fileName)
	if readErr != nil {

View on GitHub (pinned to a4447c1563)

Solutions

  1. Open the file at the reported line/column and delete the trailing comma before the closing brace/bracket
  2. Run the file through a strict JSON linter or `python -m json.tool <file>` to find all syntax issues
  3. If the file should tolerate relaxed syntax, ensure it uses the Wave config format that supports comments/relaxations expected by your Wave version

Example fix

// before (settings.json)
{
  "app:dismissarchitecturewarning": true,
}
// after
{
  "app:dismissarchitecturewarning": true
}
Defensive patterns

Strategy: validation

Validate before calling

var raw map[string]any
if err := json.Unmarshal(data, &raw); err != nil {
    var se *json.SyntaxError
    if errors.As(err, &se) {
        line, col := getLineCol(data, int(se.Offset))
        return fmt.Errorf("config JSON invalid at %d:%d — check for trailing comma", line, col)
    }
    return err
}

Try / catch

err := wconfig.SetBaseConfigValue(toMerge)
if err != nil && strings.Contains(err.Error(), "trailing comma") {
    // surface file+line to user, offer to auto-strip trailing commas
}

Prevention

When it happens

Trigger: Parsing a settings/config JSON file that contains a comma after the last element of an object or array (e.g. {"a": 1,}), via ReadWaveHomeConfigFile/GenerateSettingsMetaConsts and related generators.

Common situations: Hand-editing ~/.waveterm/config/settings.json and leaving a trailing comma after the final key; merging config snippets generated by copy-paste; JSON5 habits applied to strict JSON files.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/cf4a0e9b7d19e979. Report an issue: GitHub.