{"record":{"id":"5fa88404a4b7d75e","repo":"siyuan-note/siyuan","slug":"marshal-box-document-metadata-failed-w","errorCode":null,"errorMessage":"marshal box document metadata failed: %w","messagePattern":"marshal box document metadata failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/model/box_doc.go","lineNumber":89,"sourceCode":"\t\treturn \"\", fmt.Errorf(\"unmarshal box document metadata failed: %w\", err)\n\t}\n\tif boxDocMetaSpec != meta.Spec {\n\t\treturn \"\", fmt.Errorf(\"unsupported box document metadata spec [%d]\", meta.Spec)\n\t}\n\tif !ast.IsNodeIDPattern(meta.BoxDocID) {\n\t\treturn \"\", fmt.Errorf(\"invalid box document ID [%s]\", meta.BoxDocID)\n\t}\n\tif boxID != meta.BoxDocID {\n\t\treturn \"\", fmt.Errorf(\"box document ID [%s] does not match box ID [%s]\", meta.BoxDocID, boxID)\n\t}\n\treturn boxID, nil\n}\n\nfunc writeBoxDocID(boxID string) error {\n\tmeta := &boxDocMeta{Spec: boxDocMetaSpec, BoxDocID: boxID}\n\tdata, err := gulu.JSON.MarshalIndentJSON(meta, \"\", \"  \")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"marshal box document metadata failed: %w\", err)\n\t}\n\treturn filelock.WriteFile(boxDocMetaPath(boxID), data)\n}\n\nfunc IsBoxDocEnabled() bool {\n\treturn nil != Conf && nil != Conf.FileTree && nil != Conf.FileTree.BoxDocEnabled && *Conf.FileTree.BoxDocEnabled\n}\n\nfunc hiddenBoxDocRootIDs() (ret []string) {\n\tif IsBoxDocEnabled() || nil == Conf {\n\t\treturn\n\t}\n\tfor _, box := range Conf.GetOpenedBoxes() {\n\t\tret = append(ret, box.ID)\n\t}\n\treturn\n}\n","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/box_doc.go#L71-L107","documentation":"writeBoxDocID serializes the boxDocMeta struct to JSON before writing .siyuan/boxDoc.json; this error wraps any failure of gulu.JSON.MarshalIndentJSON. Since the struct contains only an int and a string, marshalling essentially cannot fail — this is a defensive wrap, meaning a hit points to an unexpected serialization-library or environment issue rather than user input.","triggerScenarios":"writeBoxDocID (called from ensureBoxDoc0, importSY0, or tests) where MarshalIndentJSON returns a non-nil error on {Spec:1, BoxDocID:boxID}.","commonSituations":"Effectively only internal/library anomalies; theoretical JSON encoder failure. Practically seen only during unusual environments (memory pressure) or modified gulu behavior.","solutions":["Retry the operation that writes the notebook doc metadata (re-open the notebook / re-run import)","Check the boxed error (%w chain) to identify the underlying serialization failure","Verify the gulu library version matches kernel/go.mod and rebuild; the struct contains no unmarshalable types so failure signals an environment problem"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := writeBoxDocID(boxID); err != nil {\n    // marshalling a two-field struct should not fail; log wrapped cause and retry\n    logging.LogErrorf(\"write box doc metadata for %s failed: %s\", boxID, err)\n}","preventionTips":["Keep gulu dependency versions aligned with kernel/go.mod","Retry metadata writes once on transient failure","Investigate the wrapped error if it recurs — it indicates an environment problem"],"tags":["json","serialization","notebook","internal"],"backgroundTag":"json-marshal-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"}