siyuan-note/siyuan · error
document not found:
Error message
document not found:
What it means
resolveMultimodalDocument looks up the document in the block tree (treenode.GetBlockTree on the trimmed ID) and returns 'document not found: <id>' when the lookup yields nil. It is the standard not-found signal for multimodal image APIs targeting a document.
Source
Thrown at kernel/model/assets.go:578
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 8641553a1f)
Solutions
- Verify the documentID is the root document ID and exists in the current workspace
- Refresh the block-tree index (re-index) if the document was just created
- Use a freshly fetched document ID instead of a cached one
- Check whether the document was deleted or moved to a closed notebook
Example fix
// before
result, err := model.GenerateDocumentImage(ctx, "20240101120000-abc")
// after
bt := treenode.GetBlockTree(docID) // confirm non-nil first
if bt == nil { docID = awaitFreshIndexFor(docID) }
result, err := model.GenerateDocumentImage(ctx, docID) Defensive patterns
Strategy: validation
Validate before calling
bt := treenode.GetBlockTree(strings.TrimSpace(documentID))
if bt == nil {
return fmt.Errorf("document %q not found in current workspace", documentID)
} Type guard
func docExists(documentID string) bool {
return treenode.GetBlockTree(strings.TrimSpace(documentID)) != nil
} Try / catch
res, err := model.GenerateDocumentImage(ctx, docID)
if err != nil && strings.Contains(err.Error(), "document not found") {
return fmt.Errorf("please reopen the document; it may have been deleted: %w", err)
} Prevention
- Always resolve fresh document IDs from the tree instead of caching them
- Wait for indexing completion before operating on just-created documents
- Use the root document ID, not a child block ID
- Confirm the notebook is open and the document not deleted
When it happens
Trigger: Calling ListDocumentImages, PrepareDocumentImage, or GenerateDocumentImage with a documentID that is empty/whitespace, was deleted, was not yet indexed, or is an ID from another workspace.
Common situations: Stale client-side document reference after deletion or rename, race where the document was just created but not yet indexed into the block tree, cross-workspace IDs, passing a block ID instead of the root document ID.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- document not found or empty
- document not found: %s
- duplicate document ID [%s]
- sort target document [%s] not found
- target document [%s] is unavailable
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/90664d5223e89d0e.
Report an issue: GitHub.