{"record":{"id":"a788f86fe5f6ae91","repo":"siyuan-note/siyuan","slug":"unmarshal-inline-styles-failed-w","errorCode":null,"errorMessage":"unmarshal inline styles failed: %w","messagePattern":"unmarshal inline styles failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":471,"sourceCode":"\nfunc isInlineStylesRepoPath(filePath string) bool {\n\treturn filePath == inlineStylesRepoPath\n}\n\nfunc loadInlineStyles() (ret *InlineStyles, err error) {\n\tret = newEmptyInlineStyles()\n\tdata, err := filelock.ReadFile(inlineStylesPath())\n\tif os.IsNotExist(err) {\n\t\treturn ret, nil\n\t}\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read inline styles failed: %w\", err)\n\t}\n\tif maxInlineStylesFileSize < len(data) {\n\t\treturn nil, fmt.Errorf(\"inline styles file exceeds the %d byte limit\", maxInlineStylesFileSize)\n\t}\n\tif err = gulu.JSON.UnmarshalJSON(data, ret); err != nil {\n\t\treturn nil, fmt.Errorf(\"unmarshal inline styles failed: %w\", err)\n\t}\n\tif ret.Version != 1 && ret.Version != InlineStylesVersion {\n\t\treturn nil, fmt.Errorf(\"unsupported inline styles version [%d]\", ret.Version)\n\t}\n\tret.Styles, err = normalizeInlineStyles(ret.Styles, false)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid inline styles data: %w\", err)\n\t}\n\tret.Builtin, err = normalizeInlineStyleBuiltin(ret.Builtin)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid inline styles data: %w\", err)\n\t}\n\tret.Order = normalizeInlineStyleOrder(ret.Order, ret.Styles)\n\tret.AV, err = normalizeInlineStyleAV(ret.AV, false)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid inline styles data: %w\", err)\n\t}\n\tret.Version = InlineStylesVersion","sourceCodeStart":453,"sourceCodeEnd":489,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/inline_style.go#L453-L489","documentation":"loadInlineStyles parses the inline-styles file with gulu.JSON.UnmarshalJSON into the InlineStyles struct. If the bytes are not valid JSON or do not match the expected structure, parsing fails and this wrapped error is returned, preventing malformed data from entering the styling subsystem.","triggerScenarios":"Any loader-calling API runs while the inline-styles file contains invalid JSON: truncated writes from a crash, manual editing mistakes, encoding issues (BOM, non-UTF8), or the file being overwritten by another tool.","commonSituations":"Power loss mid-write leaving a half-written file, a user hand-editing the JSON and introducing a syntax error, sync conflicts merging two JSON versions textually, or the file being replaced with exported HTML/log content by mistake.","solutions":["Validate the file as JSON (e.g. with a JSON linter) and fix the syntax error, or restore it from file history/backup","If the styles are not valuable, delete the file; the next load returns an empty default structure and it is recreated on next save","Ensure the file is UTF-8 without BOM and completely written (no truncation)","Avoid hand-editing the file while SiYuan is running; use the in-app style editor instead"],"exampleFix":"// before: truncated/corrupt JSON on disk\n{\"version\":2,\"styles\":[{\"id\":\"2024...\n// after: complete valid JSON restored from history\n{\"version\":2,\"styles\":[],\"builtin\":{},\"order\":[],\"av\":{}}","handlingStrategy":"validation","validationCode":"function inlineStylesIsValidJSON(path) {\n  try { JSON.parse(require('fs').readFileSync(path, 'utf8')); return true; }\n  catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  const styles = await api.getInlineStyles();\n} catch (e) {\n  if (String(e).includes('unmarshal inline styles failed')) {\n    // restore the file from history or delete it to reset to defaults\n  } else throw e;\n}","preventionTips":["Do not hand-edit the inline-styles file while the app is running","Save edits as UTF-8 without BOM","Use a JSON linter before putting an edited file back"],"tags":["json","parsing","corrupt-file"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}