{"record":{"id":"55cf716944182031","repo":"wavetermdev/waveterm","slug":"error-reading-config-file-v","errorCode":null,"errorMessage":"error reading config file: %v","messagePattern":"error reading config file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/wconfig/settingsconfig.go","lineNumber":848,"sourceCode":"\t\t}\n\t\treturn nil, fmt.Errorf(\"invalid number for int64: %s\", num)\n\t}\n\tif reflect.Float64 == ctype.Kind() {\n\t\tif fval, err := num.Float64(); err == nil {\n\t\t\treturn fval, nil\n\t\t}\n\t\treturn nil, fmt.Errorf(\"invalid number for float64: %s\", num)\n\t}\n\tif reflect.String == ctype.Kind() {\n\t\treturn num.String(), nil\n\t}\n\treturn nil, fmt.Errorf(\"cannot convert number to %s\", ctype)\n}\n\nfunc SetBaseConfigValue(toMerge waveobj.MetaMapType) error {\n\tm, cerrs := ReadWaveHomeConfigFile(SettingsFile)\n\tif len(cerrs) > 0 {\n\t\treturn fmt.Errorf(\"error reading config file: %v\", cerrs[0])\n\t}\n\tif m == nil {\n\t\tm = make(waveobj.MetaMapType)\n\t}\n\tfor configKey, val := range toMerge {\n\t\tctype := getConfigKeyType(configKey)\n\t\tif ctype == nil {\n\t\t\treturn fmt.Errorf(\"invalid config key: %s\", configKey)\n\t\t}\n\t\tif val == nil {\n\t\t\tdelete(m, configKey)\n\t\t} else {\n\t\t\trtype := reflect.TypeOf(val)\n\t\t\tif rtype == reflect.TypeOf(dummyNumber) {\n\t\t\t\tconvertedVal, err := convertJsonNumber(val.(json.Number), ctype)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"cannot convert %s: %v\", configKey, err)\n\t\t\t\t}","sourceCodeStart":830,"sourceCodeEnd":866,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/wconfig/settingsconfig.go#L830-L866","documentation":"SetBaseConfigValue first reads ~/.waveterm/settings.json via ReadWaveHomeConfigFile; if that read produced any ConfigError entries, the first one is wrapped as 'error reading config file: %v' and returned before any merge happens. The underlying cause is almost always a JSON syntax error in the settings file.","triggerScenarios":"Calling SetBaseConfigValue when settings.json fails to parse (syntax error, trailing comma) or otherwise reports config errors during read.","commonSituations":"Programmatically updating settings while the user has hand-broken the file; a crashed edit leaving partial JSON on disk.","solutions":["Open settings.json, fix the JSON syntax problem described in the wrapped message (line/col are included)","Validate the file with a strict JSON parser before retrying","Restore settings.json from backup or delete it to regenerate defaults, then re-run the update"],"exampleFix":"// before: settings.json contains a trailing comma, SetBaseConfigValue fails\n// after: sanitize first\nif err := validateJSONFile(settingsPath); err != nil {\n    return fmt.Errorf(\"fix settings.json first: %w\", err)\n}\nerr := wconfig.SetBaseConfigValue(toMerge)","handlingStrategy":"validation","validationCode":"data, _ := os.ReadFile(settingsPath)\nif !json.Valid(data) {\n    return fmt.Errorf(\"settings.json is not valid JSON; fix it before calling SetBaseConfigValue\")\n}","typeGuard":null,"tryCatchPattern":"if err := wconfig.SetBaseConfigValue(toMerge); err != nil {\n    if strings.Contains(err.Error(), \"error reading config file\") {\n        // settings.json on disk is broken; prompt user to fix or restore\n        return fmt.Errorf(\"repair settings.json first: %w\", err)\n    }\n    return err\n}","preventionTips":["Keep settings.json valid JSON at all times; validate on save","Don't hand-edit settings while automated writers may run","Keep a known-good backup of settings.json for quick restore"],"tags":["config","json","file-read","settings","go"],"backgroundTag":"json-syntax-error","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}