siyuan-note/siyuan · error

0

0

Error message

Query notebook failed

What it means

In RenameBox, Conf.Box(boxID) returned nil (no mounted notebook with that ID), so the function returns errors.New(Conf.Language(0)) = 'Query notebook failed'. This is the not-found / not-mounted guard that precedes the rename logic; it fires before the name-length check (796).

Source

Thrown at kernel/model/mount.go:116

	if initializeBoxDoc {
		if _, err = ensureBoxDoc0(id); err != nil {
			treenode.RemoveBlockTreesByBoxID(id)
			sql.DeleteBoxQueue(id)
			if removeErr := filelock.Remove(boxLocalPath); nil != removeErr {
				logging.LogErrorf("remove box [%s] after initializing box document failed: %s", id, removeErr)
			}
			return "", err
		}
	}
	IncSync()
	logging.LogInfof("created box [%s]", id)
	return
}

func RenameBox(boxID, name string) (err error) {
	box := Conf.Box(boxID)
	if nil == box {
		return errors.New(Conf.Language(0))
	}

	name = normalizeBoxName(name)
	if 512 < utf8.RuneCountInString(name) {
		// 限制笔记本名和文档名最大长度为 `512` https://github.com/siyuan-note/siyuan/issues/6299
		err = errors.New(Conf.Language(106))
		return
	}

	boxConf := box.GetConf()
	boxConf.Name = name
	box.Name = name
	if err = box.SaveConf(boxConf); err != nil {
		logging.LogErrorf("save box conf [%s] failed: %s", boxID, err)
		return
	}
	if err = renameBoxDoc(boxID, name); err != nil {
		logging.LogErrorf("rename box document [box=%s] failed: %s", boxID, err)

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Refresh the notebook list (ListNotebooks) and use a current, valid boxID before calling RenameBox.
  2. If the target is an encrypted notebook, ensure it is unlocked/mounted first (isEncryptedBoxMounted).
  3. Avoid calling RenameBox concurrently with RemoveBox on the same ID; serialise such operations.
  4. Validate the ID with ast.IsNodeIDPattern and confirm presence in Conf before invoking.

Example fix

// before
err := model.RenameBox(staleBoxID, name) // Language(0)

// after
if Conf.Box(boxID) == nil {
    return fmt.Errorf("notebook %s not found/mounted", boxID)
}
err := model.RenameBox(boxID, name)
Defensive patterns

Strategy: validation

Validate before calling

func notebookExists(boxID string) bool {
    if !ast.IsNodeIDPattern(boxID) { return false }
    return Conf.Box(boxID) != nil
}

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Calling RenameBox with a boxID that does not correspond to any currently mounted notebook: the notebook was removed, was never created, belongs to an unmounted encrypted notebook, or the ID is malformed but happened to escape earlier validation.

Common situations: Stale UI state referencing a deleted notebook; race between remove and rename; encrypted notebook not yet unlocked/mounted; typo or copy-paste of a wrong ID; calling rename on the user-guide notebook which may be special-cased.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/b16ad7842be37377. Report an issue: GitHub.