siyuan-note/siyuan · error

document not found:

Error message

document not found: 

What it means

resolveMultimodalDocument looks up the document in the in-memory block tree via treenode.GetBlockTree(strings.TrimSpace(documentID)). When no block-tree entry exists for the trimmed ID, it returns "document not found: <id>". This guard is shared by ListDocumentImages, PrepareDocumentImage, and GenerateDocumentImage.

Solutions

  1. Verify the ID is the document's root block ID (the .sy filename without extension), not a child block ID
  2. Check the document still exists in the doc tree and re-fetch a fresh ID if it was deleted or renamed
  3. Trim whitespace and URL-decode the ID before passing it
  4. Retry after indexing completes if the document was just created/imported

Example fix

// before
images, err := model.ListDocumentImages(blockID) // child block ID
// after
rootID := treenode.GetBlockTree(blockID).RootID // or query /api/filetree/getDocInfo
images, err = model.ListDocumentImages(rootID)
Defensive patterns

Strategy: validation

Validate before calling

docID = strings.TrimSpace(docID)
bt := treenode.GetBlockTree(docID)
if bt == nil {
    return fmt.Errorf("document %q not found in block tree", docID)
}

Try / catch

res, err := model.ListDocumentImages(docID)
if err != nil && strings.HasPrefix(err.Error(), "document not found:") {
    // re-fetch document list and use the current root ID
}

Prevention

When it happens

Trigger: Passing a documentID that is empty, whitespace-only, mistyped, refers to a deleted document, or references a block/document that has not yet been indexed into the block tree (e.g. before opening/sync completes).

Common situations: Using a block ID instead of a document (root) ID; a stale document ID cached in a plugin after the doc was removed; calling the API immediately after import before indexing finishes; an ID with stray whitespace or URL encoding.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/assets.go:582

	if err != nil {
		return GenerateDocumentImageResult{}, err
	}
	assetPath, _, err := InsertAssetBytes(bt.RootID, "ai-image"+generated.Extension, generated.Data)
	if err != nil {
		return GenerateDocumentImageResult{}, markImageExecutionUnknown(fmt.Errorf("save generated image failed: %w", err))
	}
	return GenerateDocumentImageResult{
		Artifact: ImageArtifactRef{
			Kind: "image", Path: assetPath, MIMEType: generated.MIMEType, DocumentID: bt.RootID,
		},
		RevisedPrompt: generated.RevisedPrompt,
	}, nil
}

func resolveMultimodalDocument(documentID string) (*treenode.BlockTree, error) {
	bt := treenode.GetBlockTree(strings.TrimSpace(documentID))
	if bt == nil {
		return nil, errors.New("document not found: " + documentID)
	}
	return bt, nil
}

func validateImageModel(provider *conf.Provider, imageModel *conf.Model) error {
	if provider == nil || imageModel == nil {
		return errors.New("image model is not configured")
	}
	if provider.Protocol != "" && provider.Protocol != util.OpenAIProtocolChatCompletions &&
		provider.Protocol != util.OpenAIProtocolResponses {
		return fmt.Errorf("unsupported multimodal provider protocol: %s", provider.Protocol)
	}
	return nil
}

func documentReferencesImage(rootID, assetPath string) bool {
	paths, err := DocImageAssets(rootID)
	if err != nil {

View on GitHub (pinned to 9f775e8a12)