{"record":{"id":"90664d5223e89d0e","repo":"siyuan-note/siyuan","slug":"document-not-found","errorCode":null,"errorMessage":"document not found: ","messagePattern":"document not found: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/assets.go","lineNumber":578,"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":560,"sourceCodeEnd":596,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/assets.go#L560-L596","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nresult, err := model.GenerateDocumentImage(ctx, \"20240101120000-abc\")\n// after\nbt := treenode.GetBlockTree(docID) // confirm non-nil first\nif bt == nil { docID = awaitFreshIndexFor(docID) }\nresult, err := model.GenerateDocumentImage(ctx, docID)","handlingStrategy":"validation","validationCode":"bt := treenode.GetBlockTree(strings.TrimSpace(documentID))\nif bt == nil {\n    return fmt.Errorf(\"document %q not found in current workspace\", documentID)\n}","typeGuard":"func docExists(documentID string) bool {\n    return treenode.GetBlockTree(strings.TrimSpace(documentID)) != nil\n}","tryCatchPattern":"res, err := model.GenerateDocumentImage(ctx, docID)\nif err != nil && strings.Contains(err.Error(), \"document not found\") {\n    return fmt.Errorf(\"please reopen the document; it may have been deleted: %w\", err)\n}","preventionTips":["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"],"tags":["document","not-found","image-generation"],"backgroundTag":"resource-not-found","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}