{"record":{"id":"a27c2c12c2ef7402","repo":"siyuan-note/siyuan","slug":"notebook-s-not-found","errorCode":null,"errorMessage":"notebook [%s] not found","messagePattern":"notebook \\[(.+?)\\] not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/notebook.go","lineNumber":95,"sourceCode":"\t\tid, err := model.CreateBox(name)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif _, err = model.Mount(id); err != nil {\n\t\t\treturn fmt.Errorf(\"notebook [%s] was created but could not be opened: %w\", id, err)\n\t\t}\n\t\tmodel.AppendPushReloadFiletreeEntry()\n\t\tfmt.Println(id)\n\t\treturn nil\n\t},\n}\n\nfunc formatNotebookWriteError(boxID string, err error) error {\n\tif errors.Is(err, model.ErrBoxClosed) {\n\t\treturn fmt.Errorf(\"notebook [%s] is closed; run `notebook open --id %s` first\", boxID, boxID)\n\t}\n\tif errors.Is(err, model.ErrBoxNotFound) {\n\t\treturn fmt.Errorf(\"notebook [%s] not found\", boxID)\n\t}\n\treturn err\n}\n\nvar notebookRemoveCmd = &cobra.Command{\n\tUse:   \"remove --id <id>\",\n\tShort: \"Remove a notebook\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tid, _ := cmd.Flags().GetString(\"id\")\n\t\tif id == \"\" {\n\t\t\treturn fmt.Errorf(\"--id is required\")\n\t\t}\n\n\t\tif dryRun {\n\t\t\tfmt.Printf(\"[dry-run] Would remove notebook %s\\n\", id)\n\t\t\treturn nil\n\t\t}\n","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/cli/cmd/notebook.go#L77-L113","documentation":"Thrown by formatNotebookWriteError when a notebook-mutating CLI command (create/open/remove/rename) receives model.ErrBoxNotFound from the kernel. The helper translates the low-level model error into a user-facing message naming the offending box ID. It exists so CLI users get an actionable message instead of an opaque sentinel error.","triggerScenarios":"A cobra subcommand in notebook.go calls a model.*Box function with a boxID that does not correspond to any mounted or known notebook, and the returned error is wrapped via formatNotebookWriteError(boxID, err). errors.Is(err, model.ErrBoxNotFound) is true.","commonSituations":"Passing a stale notebook ID copied from an old workspace, typos in --id, running the command against a different workspace/data dir than where the notebook lives, or referencing a notebook that was removed in another session.","solutions":["Run `notebook list` to confirm the current valid notebook IDs, then retry with a correct --id value.","Verify the workspace path the kernel is using (the --workspace flag / working dir) matches where the notebook was created.","Check that the notebook is not on a different SiYuan instance or data directory."],"exampleFix":"# before\nsiyuan notebook remove --id 202301010000-abc\ngot: notebook [202301010000-abc] not found\n# after\nsiyuan notebook list\n# pick a real id, then:\nsiyuan notebook remove --id 202405121200-realid","handlingStrategy":"try-catch","validationCode":"// Validate the notebook exists before calling a mutating model function.\nfunc notebookExists(id string) bool {\n    notebooks, err := model.ListNotebooks()\n    if err != nil {\n        return false\n    }\n    for _, nb := range notebooks {\n        if nb.ID == id {\n            return true\n        }\n    }\n    return false\n}\n\n// before calling a write op:\nif !notebookExists(boxID) {\n    return fmt.Errorf(\"refusing to operate: notebook [%s] not found\", boxID)\n}","typeGuard":"n/a (Go; guard via boolean helper above)","tryCatchPattern":"err := model.RemoveBox(boxID)\nif err != nil {\n    if errors.Is(err, model.ErrBoxNotFound) {\n        // surface a user-friendly message, optionally offer `notebook list`\n        return fmt.Errorf(\"notebook [%s] not found; run `notebook list`\", boxID)\n    }\n    return err\n}","preventionTips":["Always resolve notebook IDs from a fresh `notebook list` rather than hard-coding them.","In scripts, fail fast with set -u / unbound variable checks so an empty ID aborts early.","Treat ErrBoxNotFound and ErrBoxClosed distinctly so users get the right remediation."],"tags":["cli","notebook","validation","not-found"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}