{"record":{"id":"252639e34f0faac9","repo":"siyuan-note/siyuan","slug":"table-cell-rich-text-payload-is-not-utf-8","errorCode":null,"errorMessage":"table cell rich text payload is not UTF-8","messagePattern":"table cell rich text payload is not UTF-8","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/treenode/table_cell_rich.go","lineNumber":33,"sourceCode":"\nconst TableCellRichDocumentSpec = \"4\"\nconst TableCellRichTableAttribute = \"custom-sy-table-rich\"\n\nfunc checkTableCellRichJSON(data []byte, spec string) error {\n\ttype rawNode struct {\n\t\tType          string\n\t\tTableCellRich json.RawMessage\n\t\tChildren      []json.RawMessage\n\t}\n\tvar check func(json.RawMessage, string) error\n\tcheck = func(raw json.RawMessage, context string) error {\n\t\tvar node rawNode\n\t\tif err := json.Unmarshal(raw, &node); nil != err {\n\t\t\treturn err\n\t\t}\n\t\tif len(node.TableCellRich) > 0 {\n\t\t\tif !utf8.Valid(node.TableCellRich) {\n\t\t\t\treturn fmt.Errorf(\"table cell rich text payload is not UTF-8\")\n\t\t\t}\n\t\t\tversion, _ := strconv.Atoi(spec)\n\t\t\tif version < 4 || node.Type != \"NodeTableCell\" || context != \"row\" {\n\t\t\t\treturn fmt.Errorf(\"invalid table cell rich text document spec [%s]\", spec)\n\t\t\t}\n\t\t\tvar fields map[string]json.RawMessage\n\t\t\tif err := json.Unmarshal(node.TableCellRich, &fields); nil != err || len(fields) != 3 {\n\t\t\t\treturn fmt.Errorf(\"invalid table cell rich text payload\")\n\t\t\t}\n\t\t\tfor _, name := range []string{\"spec\", \"format\", \"content\"} {\n\t\t\t\tif len(fields[name]) == 0 || bytes.Equal(bytes.TrimSpace(fields[name]), []byte(\"null\")) {\n\t\t\t\t\treturn fmt.Errorf(\"missing table cell rich text field [%s]\", name)\n\t\t\t\t}\n\t\t\t}\n\t\t\tvar rich ast.TableCellRich\n\t\t\tif err := json.Unmarshal(node.TableCellRich, &rich); nil != err {\n\t\t\t\treturn err\n\t\t\t}","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/treenode/table_cell_rich.go#L15-L51","documentation":"While validating a serialized document that carries table-cell rich text (checkTableCellRichJSON), the TableCellRich JSON payload attached to a NodeTableCell must be valid UTF-8. If it contains invalid byte sequences it cannot be safely parsed, so validation fails before any further checks.","triggerScenarios":"Loading or importing a document whose .sy JSON contains a NodeTableCell with a TableCellRich field containing non-UTF-8 bytes — typically from binary corruption, bad encoding during external editing, or a broken third-party generator.","commonSituations":"Documents edited or generated outside SiYuan with wrong encoding, files corrupted by non-UTF-8-safe tools, or data synced from a source that mangled bytes.","solutions":["Restore the document from a snapshot/history or backup; the payload is corrupt at the byte level.","Inspect the .sy file and fix/remove the malformed TableCellRich field for that cell.","If produced by an external tool, fix that tool to emit valid UTF-8 JSON before re-importing."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if !utf8.Valid(tableCellRichBytes) { /* reject or restore from backup before loading the document */ }","typeGuard":"func validUTF8(b []byte) bool { return utf8.Valid(b) }","tryCatchPattern":null,"preventionTips":["Only edit .sy files with UTF-8-safe tools.","Validate externally generated JSON as UTF-8 before import.","Keep snapshots/backups so corrupted payloads can be restored."],"tags":["encoding","utf8","tables","rich-text"],"backgroundTag":"invalid-json-response","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"}