{"record":{"id":"3ec5aa1c849aa5b9","repo":"siyuan-note/siyuan","slug":"unsupported-document-version-type-s","errorCode":null,"errorMessage":"unsupported document version type [%s]","messagePattern":"unsupported document version type \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/history_diff.go","lineNumber":145,"sourceCode":"\t\t}\n\t\tif IsEncryptedBox(blockTree.BoxID) {\n\t\t\treturn blockTree.BoxID, nil\n\t\t}\n\t\treturn \"\", nil\n\tcase docVersionHistory:\n\t\tabsPath, err := validateHistoryPath(ref.Path)\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\tboxID := ExtractBoxIDFromHistoryPath(absPath)\n\t\tif IsEncryptedBox(boxID) {\n\t\t\treturn boxID, nil\n\t\t}\n\t\treturn \"\", nil\n\tcase docVersionSnapshot:\n\t\treturn ResolveRepoFileBoxID(ref.ID)\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"unsupported document version type [%s]\", ref.Type)\n\t}\n}\n\n// DiffDocVersions 比较同一文档的两个版本，并返回带临时差异标记的只读块 DOM。\nfunc DiffDocVersions(leftRef, rightRef *DocVersionRef) (ret *DocVersionDiffResult, err error) {\n\tif (nil != leftRef && docVersionCurrent == leftRef.Type) || (nil != rightRef && docVersionCurrent == rightRef.Type) {\n\t\tFlushTxQueue()\n\t}\n\tleft, err := loadDocVersion(leftRef)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tright, err := loadDocVersion(rightRef)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif \"\" != left.rootID && \"\" != right.rootID && left.rootID != right.rootID {\n\t\treturn nil, errors.New(\"document versions do not belong to the same document\")","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/history_diff.go#L127-L163","documentation":"ResolveDocVersionBoxID switches on the known DocVersionRef.Type values (current, history, snapshot). If the reference carries a type outside this set, it returns this formatted error naming the unknown type. It guards against unknown/future or corrupted type values.","triggerScenarios":"A DocVersionRef with a Type value not produced by the model package - e.g. an untyped/zero-value ref, a type deserialized from client JSON with an unexpected string/int, or hand-constructed constants.","commonSituations":"Plugin or script builds DocVersionRef manually with a made-up type; API client and kernel versions diverge (client sends a newer type the kernel doesn't know); JSON unmarshal left Type at its zero value.","solutions":["Use only the exported DocVersionRef type constants (docVersionCurrent / docVersionHistory / docVersionSnapshot equivalents) when constructing refs.","Check client/kernel version mismatch and upgrade the older side.","Inspect the error message for the offending type value and fix the ref producer.","Ensure JSON payloads unmarshal Type into the correct typed field, not a zero default."],"exampleFix":"// before\nref := &model.DocVersionRef{Type: \"version\", ID: id}\n// after\nref := &model.DocVersionRef{Type: model.DocVersionHistory, Path: historyPath}","handlingStrategy":"validation","validationCode":"switch ref.Type {\ncase model.DocVersionCurrent, model.DocVersionHistory, model.DocVersionSnapshot:\n    // ok\ndefault:\n    return fmt.Errorf(\"unsupported version type %q\", ref.Type)\n}\nboxID, err := model.ResolveDocVersionBoxID(ref)","typeGuard":"func knownVersionType(t model.DocVersionType) bool {\n    return t == model.DocVersionCurrent || t == model.DocVersionHistory || t == model.DocVersionSnapshot\n}","tryCatchPattern":"boxID, err := model.ResolveDocVersionBoxID(ref)\nif err != nil {\n    var uerr *fmt.Errorf\n    if strings.HasPrefix(err.Error(), \"unsupported document version type\") {\n        return fmt.Errorf(\"upgrade client: kernel does not know type %q\", ref.Type)\n    }\n    return err\n}","preventionTips":["Use only exported type constants","Keep client and kernel versions aligned","Verify JSON unmarshal maps Type to the typed field, not zero"],"tags":["validation","enum","document-history","api-versioning"],"backgroundTag":"unsupported-enum-value","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"}