siyuan-note/siyuan · error

current document ID is invalid

Error message

current document ID is invalid

What it means

For a docVersionCurrent reference, ResolveDocVersionBoxID validates that ref.ID looks like a node ID (ast.IsNodeIDPattern) before looking it up in the block tree. If the ID string is not a well-formed node ID, this error is returned; the reference is malformed, not merely unknown.

Solutions

  1. Pass the document's root block ID (from GetDocID / block tree) in DocVersionRef.ID.
  2. Validate the ID client-side with a node-ID pattern check (same rule as ast.IsNodeIDPattern: length-20 [0-9a-z]{20}-style ID) before calling.
  3. If the value came from a URL, check encoding/decoding did not corrupt it.
  4. Log the offending ref.ID and correct the producing code path.

Example fix

// before
ref := &model.DocVersionRef{Type: model.DocVersionCurrent, ID: docPath}
// after
ref := &model.DocVersionRef{Type: model.DocVersionCurrent, ID: docRootID /* 20-char node ID */}
Defensive patterns

Strategy: validation

Validate before calling

var nodeIDPattern = regexp.MustCompile(`^\d{14}-[0-9a-z]{6}$`)
if !nodeIDPattern.MatchString(ref.ID) {
    return fmt.Errorf("%q is not a valid node ID", ref.ID)
}
boxID, err := model.ResolveDocVersionBoxID(ref)

Type guard

func isNodeIDLike(s string) bool { return len(s) == 21 && s[14] == '-' }

Try / catch

boxID, err := model.ResolveDocVersionBoxID(ref)
if err != nil {
    if strings.Contains(err.Error(), "invalid") {
        return fmt.Errorf("bad ref.ID %q: %w", ref.ID, err)
    }
    return err
}

Prevention

When it happens

Trigger: ResolveDocVersionBoxID receives a DocVersionRef with Type == docVersionCurrent and ref.ID that is empty, truncated, URL-damaged, or not a node-ID-shaped string (e.g. a file path or human title passed instead of a block ID).

Common situations: Client passed a document path instead of its ID; ID truncated by string manipulation; copy-paste dropped characters; plugin constructed the ref manually with the wrong field; query param URL-decoding mangled the ID.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/0d8cb4f281843567. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/history_diff.go:122

	start      int
	end        int
	storedRuns []string
	signature  string
}

type docDiffLCSBudget struct {
	remaining int
}

// ResolveDocVersionBoxID 返回文档版本引用中明确记录的加密笔记本 ID。
func ResolveDocVersionBoxID(ref *DocVersionRef) (string, error) {
	if ref == nil {
		return "", errors.New("document version is required")
	}
	switch ref.Type {
	case docVersionCurrent:
		if !ast.IsNodeIDPattern(ref.ID) {
			return "", errors.New("current document ID is invalid")
		}
		blockTree := treenode.GetBlockTree(ref.ID)
		if blockTree == nil {
			return "", ErrTreeNotFound
		}
		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
		}

View on GitHub (pinned to 9f775e8a12)