{"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/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L453-L489","documentation":"Error from loadInlineStyles when the persisted inline-styles JSON file exists and is within the size limit but fails gulu.JSON.UnmarshalJSON — the file is corrupt (truncated write or manual edit), so inline styles cannot be loaded.","triggerScenarios":"Any inline-styles API when data/storage inline styles file contains malformed JSON (truncated write, manual editing mistake, wrong file restored).","commonSituations":"Editing the JSON by hand with a syntax error, an interrupted kernel write leaving a truncated file, or pasting another config's content into it.","solutions":["Validate the file JSON syntax with a JSON linter and fix the syntax error","Restore the file from backup or sync history","Delete the corrupt file; the kernel will treat it as missing and start with defaults"],"exampleFix":"// before: file contains truncated JSON\n{\"version\":2,\"styles\":[{\"id\":\"20240101120000-abc\n// after: complete valid JSON (or delete the file to regenerate)\n{\"version\":2,\"styles\":[]}","handlingStrategy":"validation","validationCode":"const parsed = JSON.parse(fs.readFileSync(inlineStylesPath, 'utf8')); // throws before API call if malformed","typeGuard":"const looksLikeInlineStyles = (o) => o && typeof o === 'object' && Array.isArray(o.styles);","tryCatchPattern":"try {\n  await fetchPost('/api/attr/getInlineStyles', {});\n} catch (e) {\n  if (String(e).includes('unmarshal inline styles failed')) {\n    // restore file from backup or delete it to regenerate defaults\n  }\n}","preventionTips":["Validate JSON after every manual edit","Let the kernel write the file rather than editing it in place","Keep a known-good backup of the file"],"tags":["json","inline-styles","corruption"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}