siyuan-note/siyuan · error

notebook not found: %s

Error message

notebook not found: %s

What it means

Returned by the `notebook set-icon` subcommand after it calls model.ListNotebooks and fails to find any notebook whose ID matches the provided --id. The lookup prevents silently writing an icon for a non-existent notebook.

Source

Thrown at kernel/cli/cmd/notebook.go:242

		}
		if icon == "" {
			return fmt.Errorf("--icon is required")
		}

		// 校验笔记本存在,避免对一个不存在的 id 静默写入图标。
		exists := false
		notebooks, err := model.ListNotebooks()
		if err != nil {
			return err
		}
		for _, nb := range notebooks {
			if nb.ID == id {
				exists = true
				break
			}
		}
		if !exists {
			return fmt.Errorf("notebook not found: %s", id)
		}

		if dryRun {
			fmt.Printf("[dry-run] Would set notebook %s icon to %s\n", id, icon)
			return nil
		}

		// SetBoxIcon 内部对自定义图片名做 XSS 过滤。
		model.SetBoxIcon(id, icon)

		switch outputFormat {
		case "json":
			data, _ := json.MarshalIndent(map[string]string{"id": id, "icon": icon}, "", "  ")
			fmt.Println(string(data))
		default:
			fmt.Printf("%s\t%s\n", id, icon)
		}
		return nil

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Run `notebook list` and copy the exact ID, then retry.
  2. Verify the kernel is pointed at the correct workspace/data directory.
  3. If scripting, validate the ID exists before calling set-icon.

Example fix

# before
siyuan notebook set-icon --id stale-id --icon 1f4ca
got: notebook not found: stale-id
# after
siyuan notebook list  # confirm real id
siyuan notebook set-icon --id 202405121200-realid --icon 1f4ca
Defensive patterns

Strategy: validation

Validate before calling

func notebookExists(id string) bool {
    nbs, err := model.ListNotebooks()
    if err != nil {
        return false
    }
    for _, nb := range nbs {
        if nb.ID == id {
            return true
        }
    }
    return false
}

if !notebookExists(id) {
    return fmt.Errorf("will not set icon: notebook %s not found", id)
}

Type guard

n/a (Go; use the boolean helper above)

Try / catch

n/a (the CLI handler performs the lookup itself; callers should pre-check)

Prevention

When it happens

Trigger: Passing a --id that does not match any nb.ID in the result of model.ListNotebooks(); the `exists` flag stays false and the handler returns this error before reaching SetBoxIcon.

Common situations: Stale or typo'd notebook ID, wrong workspace, or the notebook was removed/renamed in another session since the ID was obtained.

Related errors


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