{"record":{"id":"9c8e7d7c10f2e83b","repo":"laurent22/joplin","slug":"no-notebook-selected","errorCode":null,"errorMessage":"No notebook selected.","messagePattern":"No notebook selected\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/app-cli/app/app.ts","lineNumber":103,"sourceCode":"\tpublic async loadItems(type: FolderOrNoteType, pattern: string, options: { parent?: FolderEntity } | null = null): Promise<(FolderEntity | NoteEntity)[]> {\n\t\tif (type === 'folderOrNote') {\n\t\t\tconst folders: FolderEntity[] = await this.loadItems(ModelType.Folder, pattern, options);\n\t\t\tif (folders.length) return folders;\n\t\t\treturn await this.loadItems(ModelType.Note, pattern, options);\n\t\t}\n\n\t\tpattern = pattern ? pattern.toString() : '';\n\n\t\tif (type === ModelType.Folder && (pattern === Folder.conflictFolderTitle() || pattern === Folder.conflictFolderId())) return [Folder.conflictFolder()];\n\n\t\tif (!options) options = {};\n\n\t\tconst parent = options.parent ? options.parent : app().currentFolder();\n\t\tconst ItemClass = BaseItem.itemClass(type);\n\n\t\tif (type === ModelType.Note && pattern.indexOf('*') >= 0) {\n\t\t\t// Handle it as pattern\n\t\t\tif (!parent) throw new Error(_('No notebook selected.'));\n\t\t\treturn await Note.previews(parent.id, { titlePattern: pattern });\n\t\t} else {\n\t\t\t// Single item\n\t\t\tlet item = null;\n\t\t\tif (type === ModelType.Note) {\n\t\t\t\tif (!parent) throw new Error(_('No notebook has been specified.'));\n\t\t\t\titem = await (ItemClass as typeof Note).loadFolderNoteByField(parent.id, 'title', pattern);\n\t\t\t} else {\n\t\t\t\titem = await ItemClass.loadByTitle(pattern);\n\t\t\t}\n\t\t\tif (item) return [item];\n\n\t\t\titem = await ItemClass.load(pattern); // Load by id\n\t\t\tif (item) return [item];\n\n\t\t\tif (pattern.length >= 2) {\n\t\t\t\treturn await ItemClass.loadByPartialId(pattern);\n\t\t\t}","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/laurent22/joplin/blob/2654b33620775080d1d59c552259d41e33dad3d2/packages/app-cli/app/app.ts#L85-L121","documentation":"In App.loadItems, when a note pattern contains '*' it is treated as a wildcard title search scoped to a parent notebook via Note.previews(parent.id, ...). The parent is options.parent or app().currentFolder(); if neither is set the call throws 'No notebook selected.'. The message is i18n-translated.","triggerScenarios":"Running a wildcard note search (e.g. 'ls *' or 'cat *note*') before any notebook is selected, with no options.parent supplied programmatically.","commonSituations":"First run of a session with no notebook chosen; all notebooks deleted; a script that calls loadItems with a wildcard but does not pass options.parent.","solutions":["Select a notebook first: 'use <notebook>'.","Pass options.parent explicitly when calling loadItems from code.","Create a notebook if none exist: 'mkbook <name>'."],"exampleFix":"// before\n//   const notes = await app().loadItems(ModelType.Note, '*todo*'); // throws 'No notebook selected.'\n// after\n//   await app().switchCurrentFolder(folderId); // or 'use <notebook>' in CLI\n//   const notes = await app().loadItems(ModelType.Note, '*todo*');","handlingStrategy":"validation","validationCode":"const parent = options?.parent ?? app().currentFolder();\nif (pattern.includes('*') && !parent) {\n  throw new Error('Select a notebook before using a wildcard note search.');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await app().loadItems(ModelType.Note, pattern);\n} catch (e) {\n  if (/No notebook selected/.test(e.message)) {\n    await app().switchCurrentFolder(defaultFolderId);\n  }\n}","preventionTips":["Always run 'use <notebook>' (or set options.parent) before wildcard note searches.","In scripts, pass options.parent explicitly rather than relying on GUI state."],"tags":["cli","notebook","wildcard-search","i18n"],"backgroundTag":null,"analyzedSha":"2654b33620775080d1d59c552259d41e33dad3d2","analyzedAt":"2026-08-12T14:26:46.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}