{"record":{"id":"48f36ca91c8418c1","repo":"micro-editor/micro","slug":"error-reading-settings-json-s","errorCode":null,"errorMessage":"Error reading settings.json: %s","messagePattern":"Error reading settings\\.json: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/settings.go","lineNumber":254,"sourceCode":"\t}\n\treturn err\n}\n\nfunc ReadSettings() error {\n\tparsedSettings = make(map[string]any)\n\tfilename := filepath.Join(ConfigDir, \"settings.json\")\n\tif _, e := os.Stat(filename); e == nil {\n\t\tinput, err := os.ReadFile(filename)\n\t\tif err != nil {\n\t\t\tsettingsParseError = true\n\t\t\treturn errors.New(\"Error reading settings.json file: \" + err.Error())\n\t\t}\n\t\tif !strings.HasPrefix(string(input), \"null\") {\n\t\t\t// Unmarshal the input into the parsed map\n\t\t\terr = json5.Unmarshal(input, &parsedSettings)\n\t\t\tif err != nil {\n\t\t\t\tsettingsParseError = true\n\t\t\t\treturn errors.New(\"Error reading settings.json: \" + err.Error())\n\t\t\t}\n\t\t\terr = validateParsedSettings()\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc ParsedSettings() map[string]any {\n\ts := make(map[string]any)\n\tfor k, v := range parsedSettings {\n\t\tif strings.HasPrefix(reflect.TypeOf(v).String(), \"map\") {\n\t\t\tcontinue\n\t\t}\n\t\ts[k] = v\n\t}","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/micro-editor/micro/blob/1c8b82b32e408a5faf340039ed92d5266bea3293/internal/config/settings.go#L236-L272","documentation":"Returned by config.ReadSettings when the contents of settings.json cannot be unmarshalled by the JSON5 parser. JSON5 permits comments, trailing commas and unquoted keys, but the file must still be structurally valid; the parser's message (offset/position included) is wrapped verbatim. settingsParseError is set, protecting the file from being overwritten by in-session changes.","triggerScenarios":"An unbalanced brace/bracket, a stray comma between pairs in strict positions JSON5 disallows, an unterminated string, or a literal like {'a': undef} — anything json5.Unmarshal rejects at internal/config/settings.go:254. Note a file starting with the literal text 'null' is skipped entirely.","commonSituations":"Hand-editing settings.json and losing a brace, pasting config snippets from websites that include smart quotes or HTML entities, or a crashed concurrent write truncating the file.","solutions":["Open the file and jump to the offset the parser reports; fix or remove the malformed fragment.","Validate quickly: run `micro ~/.config/micro/settings.json` in a fresh instance — JSON5 comments are fine, so you can keep notes.","If hopeless, back up and start over: mv settings.json settings.json.bak and let micro regenerate defaults, then re-add your options incrementally.","After fixing, confirm no more error on startup and that settings changes persist again (settingsParseError clears on next clean load)."],"exampleFix":"// before (~/.config/micro/settings.json):\n{ \"tabsize\": 4, \"autosave\": true,   // trailing comma then EOF -> parse error\n\n// after:\n{\n  \"tabsize\": 4,\n  \"autosave\": true\n}","handlingStrategy":"validation","validationCode":"import \"github.com/yosida95/uritemplate/v3\" // no — use a JSON5 validator:\nimport \"github.com/titanous/json5\"\n\nfunc validJSON5Settings(data []byte) bool {\n    var v map[string]any\n    return json5.Unmarshal(data, &v) == nil\n}\n\n// before saving a generated settings.json:\nif !validJSON5Settings(out) { /* regenerate from defaults */ }","typeGuard":null,"tryCatchPattern":"if err := config.ReadSettings(); err != nil {\n    if strings.HasPrefix(err.Error(), \"Error reading settings.json:\") {\n        // parse failure: back up file, restore last good copy or defaults, re-run ReadSettings\n    }\n}","preventionTips":["Edit settings.json inside micro itself (JSON5 comments allowed) so brackets stay balanced.","Keep a known-good copy (settings.json.good) and restore on parse failure.","Write settings programmatically with a JSON/JSON5 encoder rather than string concatenation."],"tags":["settings","json5","parsing","config","startup"],"backgroundTag":null,"analyzedSha":"1c8b82b32e408a5faf340039ed92d5266bea3293","analyzedAt":"2026-08-15T20:01:45.134Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}