{"record":{"id":"46ca06230685e867","repo":"siyuan-note/siyuan","slug":"conf-language-71","errorCode":null,"errorMessage":"Conf.Language(71)","messagePattern":"Conf\\.Language\\(71\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/upload.go","lineNumber":43,"sourceCode":"\t\"path\"\n\t\"path/filepath\"\n\t\"strings\"\n\n\t\"github.com/88250/gulu\"\n\t\"github.com/88250/lute/ast\"\n\t\"github.com/gin-gonic/gin\"\n\t\"github.com/siyuan-note/filelock\"\n\t\"github.com/siyuan-note/logging\"\n\t\"github.com/siyuan-note/siyuan/kernel/cache\"\n\t\"github.com/siyuan-note/siyuan/kernel/treenode\"\n\t\"github.com/siyuan-note/siyuan/kernel/util\"\n)\n\n// InsertAssetBytes 将内存中的资源直接写入目标文档资源目录，避免生成内容经过明文临时文件。\nfunc InsertAssetBytes(id, fileName string, data []byte) (assetPath string, created bool, err error) {\n\tbt := treenode.GetBlockTree(id)\n\tif bt == nil {\n\t\treturn \"\", false, errors.New(Conf.Language(71))\n\t}\n\tif len(data) == 0 {\n\t\treturn \"\", false, errors.New(\"asset data is empty\")\n\t}\n\n\tbaseName := filepath.Base(fileName)\n\tfName := util.FilterUploadFileName(baseName)\n\text := strings.ToLower(filepath.Ext(fName))\n\tfName = strings.TrimSuffix(fName, filepath.Ext(fName)) + ext\n\tif fName == \"\" || fName == \".\" || ext == \"\" {\n\t\treturn \"\", false, errors.New(\"invalid asset filename\")\n\t}\n\n\tdocDirLocalPath := filepath.Join(util.DataDir, bt.BoxID, path.Dir(bt.Path))\n\tassetsDirPath := getAssetsDir(filepath.Join(util.DataDir, bt.BoxID), docDirLocalPath)\n\tif err = os.MkdirAll(assetsDirPath, 0755); err != nil {\n\t\treturn \"\", false, err\n\t}","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/upload.go#L25-L61","documentation":"InsertAssetBytes writes in-memory asset bytes (e.g. generated images/HTML assets) directly into a target document's asset directory. It first resolves the document's block tree via treenode.GetBlockTree(id); a nil result means no document with that ID is loaded in the block tree, so the destination is unknown and the localized message Conf.Language(71) ('document not found') is returned.","triggerScenarios":"Calling InsertAssetBytes with an id for a document that is not indexed — callers assetCreateHTML and GenerateDocumentImage pass a doc ID whose block-tree entry is missing (document deleted concurrently, ID typo, or tree not yet indexed after creation/import).","commonSituations":"Generating an image into a document that was deleted or renamed (ID changed) mid-operation; pasting/generating content into a just-created document before indexing completes; plugin/API callers using a stale or wrong document ID; corrupted blocktree.db missing the entry.","solutions":["Verify the document ID exists and is open/indexed (check the .sy file and blocktree) before inserting assets","Refresh/rebuild the index (Reindex) so the block tree contains the document","Re-run the generating action (image export, HTML asset creation) — the source document may have been deleted concurrently","If blocktree.db is corrupted, rebuild the index from the .sy files"],"exampleFix":"// before\nassetPath, created, err := model.InsertAssetBytes(docID, \"img.png\", data) // errors Conf.Language(71)\n// after\nif bt := treenode.GetBlockTree(docID); bt == nil {\n    logging.LogWarnf(\"doc %s not indexed; skip asset insert\", docID)\n    return\n}\nassetPath, created, err := model.InsertAssetBytes(docID, \"img.png\", data)","handlingStrategy":"validation","validationCode":"// check the document is indexed before inserting assets\nif treenode.GetBlockTree(docID) == nil {\n    return fmt.Errorf(\"document %s is not loaded/indexed; abort asset insert\", docID)\n}","typeGuard":"func docExists(id string) bool { return treenode.GetBlockTree(id) != nil }","tryCatchPattern":"assetPath, created, err := model.InsertAssetBytes(docID, name, data)\nif err != nil {\n    logging.LogErrorf(\"insert asset into doc %s failed: %v\", docID, err)\n    // surface a localized 'document not found' message to the user and abort gracefully\n    return err\n}","preventionTips":["Resolve document IDs right before use; never cache IDs across delete/rename operations","After creating or importing a document, wait for indexing before generating assets into it","Rebuild the index if blocktree lookups fail for known-existing documents"],"tags":["document","asset","not-found","index"],"backgroundTag":"entity-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"}