{"record":{"id":"90664d5223e89d0e","repo":"siyuan-note/siyuan","slug":"document-not-found","errorCode":null,"errorMessage":"document not found: ","messagePattern":"document not found: ","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/assets.go","lineNumber":582,"sourceCode":"\tif err != nil {\n\t\treturn GenerateDocumentImageResult{}, err\n\t}\n\tassetPath, _, err := InsertAssetBytes(bt.RootID, \"ai-image\"+generated.Extension, generated.Data)\n\tif err != nil {\n\t\treturn GenerateDocumentImageResult{}, markImageExecutionUnknown(fmt.Errorf(\"save generated image failed: %w\", err))\n\t}\n\treturn GenerateDocumentImageResult{\n\t\tArtifact: ImageArtifactRef{\n\t\t\tKind: \"image\", Path: assetPath, MIMEType: generated.MIMEType, DocumentID: bt.RootID,\n\t\t},\n\t\tRevisedPrompt: generated.RevisedPrompt,\n\t}, nil\n}\n\nfunc resolveMultimodalDocument(documentID string) (*treenode.BlockTree, error) {\n\tbt := treenode.GetBlockTree(strings.TrimSpace(documentID))\n\tif bt == nil {\n\t\treturn nil, errors.New(\"document not found: \" + documentID)\n\t}\n\treturn bt, nil\n}\n\nfunc validateImageModel(provider *conf.Provider, imageModel *conf.Model) error {\n\tif provider == nil || imageModel == nil {\n\t\treturn errors.New(\"image model is not configured\")\n\t}\n\tif provider.Protocol != \"\" && provider.Protocol != util.OpenAIProtocolChatCompletions &&\n\t\tprovider.Protocol != util.OpenAIProtocolResponses {\n\t\treturn fmt.Errorf(\"unsupported multimodal provider protocol: %s\", provider.Protocol)\n\t}\n\treturn nil\n}\n\nfunc documentReferencesImage(rootID, assetPath string) bool {\n\tpaths, err := DocImageAssets(rootID)\n\tif err != nil {","sourceCodeStart":564,"sourceCodeEnd":600,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/assets.go#L564-L600","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Verify the ID is the document's root block ID (the .sy filename without extension), not a child block ID","Check the document still exists in the doc tree and re-fetch a fresh ID if it was deleted or renamed","Trim whitespace and URL-decode the ID before passing it","Retry after indexing completes if the document was just created/imported"],"exampleFix":"// before\nimages, err := model.ListDocumentImages(blockID) // child block ID\n// after\nrootID := treenode.GetBlockTree(blockID).RootID // or query /api/filetree/getDocInfo\nimages, err = model.ListDocumentImages(rootID)","handlingStrategy":"validation","validationCode":"docID = strings.TrimSpace(docID)\nbt := treenode.GetBlockTree(docID)\nif bt == nil {\n    return fmt.Errorf(\"document %q not found in block tree\", docID)\n}","typeGuard":null,"tryCatchPattern":"res, err := model.ListDocumentImages(docID)\nif err != nil && strings.HasPrefix(err.Error(), \"document not found:\") {\n    // re-fetch document list and use the current root ID\n}","preventionTips":["Always use the document's root ID (the .sy filename), never a child block ID","Refresh cached document IDs after deletions/renames or sync","Wait for indexing to finish before calling multimodal document APIs on newly imported docs"],"tags":["document","lookup","go"],"backgroundTag":"entity-not-found","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"}