siyuan-note/siyuan · error

--icon is required

Error message

--icon is required

What it means

Argument validation in the cobra notebookSetIcon RunE: fires when the --icon flag is empty (the --id check precedes it). Setting a notebook icon requires an icon value — an emoji hex codepoint, emoji character, image path, or URL; omitting --icon is the faulting usage.

Solutions

  1. Re-run with `--icon <icon>` (the notebook icon value)
  2. Confirm the icon argument is a valid icon identifier for the configured icon set
  3. Test with `--dry-run` to preview the change

Example fix

// before
siyuan notebook set-icon --id 20240101120000-abcdefg
// after
siyuan notebook set-icon --id 20240101120000-abcdefg --icon "1f4d8"
Defensive patterns

Strategy: validation

Validate before calling

if [ -z "$ICON" ]; then echo "--icon is required"; exit 1; fi
siyuan notebook set-icon --id "$NB_ID" --icon "$ICON"

Type guard

const hasIcon = (v) => typeof v === "string" && v.length > 0;

Try / catch

try { run(`siyuan notebook set-icon --id ${id} --icon ${icon}`); } catch (e) { console.error(e.message); }

Prevention

When it happens

Trigger: Running `notebook set-icon --id <id>` without `--icon`, or with `--icon ""`.

Common situations: Shell variable holding the icon name is unset; forgetting the emoji/icon argument in batch scripts.

Understand the failure class

Background: "no subcommand specified" and "... is required": CLI errors when a required argument is missing — this error's family across 13 libraries.

Related errors


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

Appendix: source

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

	for _, b := range boxes {
		fmt.Fprintf(w, "%s\t%s\t%v\t%d\n", b.ID, b.Name, b.Closed, b.Sort)
	}
	w.Flush()
}

// notebookSetIconCmd 设置笔记本图标。
// icon 取值格式:emoji hex 码点(如 "1f4ca")、emoji 字符、自定义图片路径、网络图片 URL 或动态图标 URL。
var notebookSetIconCmd = &cobra.Command{
	Use:   "set-icon --id <id> --icon <icon>",
	Short: "Set a notebook icon",
	RunE: func(cmd *cobra.Command, args []string) error {
		id, _ := cmd.Flags().GetString("id")
		icon, _ := cmd.Flags().GetString("icon")
		if id == "" {
			return fmt.Errorf("--id is required")
		}
		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)
		}

View on GitHub (pinned to 9f775e8a12)