siyuan-note/siyuan · error

Conf.Language(71)

Error message

Conf.Language(71)

What it means

InsertAssetBytes writes in-memory asset bytes directly into the target document's assets directory. It first resolves the document ID via treenode.GetBlockTree; if the ID does not exist in the block tree the call fails with the localized 'block not found' message (Conf.Language(71)). The library refuses to guess a destination for an unknown document.

Solutions

  1. Verify the document exists before inserting: check that /api/filetree/getDocByID (or treenode.GetBlockTree) returns the block for the id
  2. Re-fetch the current document ID from the UI/kernel instead of caching it across operations
  3. For encrypted notebooks, ensure the notebook is opened in the workspace before inserting assets
  4. Recreate the document if it was deleted, and capture its new ID
  5. Surface the localized message to the user and abort the insert rather than writing to a default location

Example fix

// before
assetPath, _, err := model.InsertAssetBytes(docID, "img.png", data)
// after
if bt := treenode.GetBlockTree(docID); bt == nil {
    return fmt.Errorf("document %s does not exist; open or recreate it first", docID)
}
assetPath, _, err := model.InsertAssetBytes(docID, "img.png", data)
Defensive patterns

Strategy: validation

Validate before calling

func docExists(id string) bool { return treenode.GetBlockTree(id) != nil }
// HTTP equivalent: POST /api/filetree/getDocByID {"id": docID} returns non-error

Type guard

func validDocID(id string) bool {
    return id != "" && treenode.GetBlockTree(id) != nil
}

Try / catch

assetPath, created, err := model.InsertAssetBytes(docID, name, data)
if err != nil && err.Error() == model.Conf.Language(71) {
    // block not found: refresh doc ID or open the encrypted notebook, then retry once
}

Prevention

When it happens

Trigger: Calling InsertAssetBytes(id, fileName, data) with an id that is not a live block/document ID — a stale ID from a deleted document, a typo'd ID, or an ID from an encrypted notebook that is not currently open (its tree is not loaded). Called by assetCreateHTML and GenerateDocumentImage.

Common situations: Plugin/AI code generating images into a document that was closed or deleted while processing; race between fetching a document ID and inserting into it; working with encrypted notebooks whose block tree lookup needs the notebook open.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/46ca06230685e867. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/upload.go:44

	"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 9f775e8a12)