siyuan-note/siyuan · error
Conf.Language(71)
Error message
Conf.Language(71)
What it means
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.
Source
Thrown at kernel/model/upload.go:43
"path"
"path/filepath"
"strings"
"github.com/88250/gulu"
"github.com/88250/lute/ast"
"github.com/gin-gonic/gin"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/cache"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
)
// InsertAssetBytes 将内存中的资源直接写入目标文档资源目录,避免生成内容经过明文临时文件。
func InsertAssetBytes(id, fileName string, data []byte) (assetPath string, created bool, err error) {
bt := treenode.GetBlockTree(id)
if bt == nil {
return "", false, errors.New(Conf.Language(71))
}
if len(data) == 0 {
return "", false, errors.New("asset data is empty")
}
baseName := filepath.Base(fileName)
fName := util.FilterUploadFileName(baseName)
ext := strings.ToLower(filepath.Ext(fName))
fName = strings.TrimSuffix(fName, filepath.Ext(fName)) + ext
if fName == "" || fName == "." || ext == "" {
return "", false, errors.New("invalid asset filename")
}
docDirLocalPath := filepath.Join(util.DataDir, bt.BoxID, path.Dir(bt.Path))
assetsDirPath := getAssetsDir(filepath.Join(util.DataDir, bt.BoxID), docDirLocalPath)
if err = os.MkdirAll(assetsDirPath, 0755); err != nil {
return "", false, err
}View on GitHub (pinned to 8641553a1f)
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
Example fix
// before
assetPath, created, err := model.InsertAssetBytes(docID, "img.png", data) // errors Conf.Language(71)
// after
if bt := treenode.GetBlockTree(docID); bt == nil {
logging.LogWarnf("doc %s not indexed; skip asset insert", docID)
return
}
assetPath, created, err := model.InsertAssetBytes(docID, "img.png", data) Defensive patterns
Strategy: validation
Validate before calling
// check the document is indexed before inserting assets
if treenode.GetBlockTree(docID) == nil {
return fmt.Errorf("document %s is not loaded/indexed; abort asset insert", docID)
} Type guard
func docExists(id string) bool { return treenode.GetBlockTree(id) != nil } Try / catch
assetPath, created, err := model.InsertAssetBytes(docID, name, data)
if err != nil {
logging.LogErrorf("insert asset into doc %s failed: %v", docID, err)
// surface a localized 'document not found' message to the user and abort gracefully
return err
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
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
- document [%s] could not be read
- Failed to insert asset file, please reopen the document
- document not found or empty
- document not found: %s
- document not found:
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/46ca06230685e867.
Report an issue: GitHub.