siyuan-note/siyuan · error
unsupported document version type
Error message
unsupported document version type [%s]
What it means
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.
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.
Example fix
// before
ref := &model.DocVersionRef{Type: "version", ID: id}
// after
ref := &model.DocVersionRef{Type: model.DocVersionHistory, Path: historyPath} Defensive patterns
Strategy: validation
Validate before calling
switch ref.Type {
case model.DocVersionCurrent, model.DocVersionHistory, model.DocVersionSnapshot:
// ok
default:
return fmt.Errorf("unsupported version type %q", ref.Type)
}
boxID, err := model.ResolveDocVersionBoxID(ref) Type guard
func knownVersionType(t model.DocVersionType) bool {
return t == model.DocVersionCurrent || t == model.DocVersionHistory || t == model.DocVersionSnapshot
} Try / catch
boxID, err := model.ResolveDocVersionBoxID(ref)
if err != nil {
var uerr *fmt.Errorf
if strings.HasPrefix(err.Error(), "unsupported document version type") {
return fmt.Errorf("upgrade client: kernel does not know type %q", ref.Type)
}
return err
} Prevention
- Use only exported type constants
- Keep client and kernel versions aligned
- Verify JSON unmarshal maps Type to the typed field, not zero
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- current document ID is invalid
- document version is required
- document versions do not belong to the same document
- ErrInvalidColumnAlign
- Field [mode] must be 0 or 1
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/3ec5aa1c849aa5b9.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/history_diff.go:145
}
if IsEncryptedBox(blockTree.BoxID) {
return blockTree.BoxID, nil
}
return "", nil
case docVersionHistory:
absPath, err := validateHistoryPath(ref.Path)
if err != nil {
return "", err
}
boxID := ExtractBoxIDFromHistoryPath(absPath)
if IsEncryptedBox(boxID) {
return boxID, nil
}
return "", nil
case docVersionSnapshot:
return ResolveRepoFileBoxID(ref.ID)
default:
return "", fmt.Errorf("unsupported document version type [%s]", ref.Type)
}
}
// DiffDocVersions 比较同一文档的两个版本,并返回带临时差异标记的只读块 DOM。
func DiffDocVersions(leftRef, rightRef *DocVersionRef) (ret *DocVersionDiffResult, err error) {
if (nil != leftRef && docVersionCurrent == leftRef.Type) || (nil != rightRef && docVersionCurrent == rightRef.Type) {
FlushTxQueue()
}
left, err := loadDocVersion(leftRef)
if err != nil {
return nil, err
}
right, err := loadDocVersion(rightRef)
if err != nil {
return nil, err
}
if "" != left.rootID && "" != right.rootID && left.rootID != right.rootID {
return nil, errors.New("document versions do not belong to the same document")View on GitHub (pinned to 9f775e8a12)