{"record":{"id":"d83c5f28199821e1","repo":"laurent22/joplin","slug":"cannot-find-s-d83c5f","errorCode":null,"errorMessage":"Cannot find \"%s\".","messagePattern":"Cannot find \"(.+?)\"\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/app-cli/app/command-use.ts","lineNumber":22,"sourceCode":"import { ModelType } from '@joplin/lib/BaseModel';\nimport Folder from '@joplin/lib/models/Folder';\n\nclass Command extends BaseCommand {\n\tpublic override usage() {\n\t\treturn 'use <notebook>';\n\t}\n\n\tpublic override description() {\n\t\treturn _('Switches to [notebook] - all further operations will happen within this notebook.');\n\t}\n\n\tpublic override compatibleUis() {\n\t\treturn ['cli'];\n\t}\n\n\tpublic override async action(args: { 'notebook': string }) {\n\t\tconst folder = await app().loadItem(ModelType.Folder, args['notebook']);\n\t\tif (!folder) throw new Error(_('Cannot find \"%s\".', args['notebook']));\n\n\t\t// Auto-expand parent folders in GUI if present\n\t\tif (app().gui() && app().gui().widget && app().gui().widget('folderList')) {\n\t\t\tconst folderListWidget = app().gui().widget('folderList');\n\t\t\tif (folderListWidget.expandToFolder) {\n\t\t\t\t// Get all folders to pass to expandToFolder\n\t\t\t\tconst folders = await Folder.all();\n\t\t\t\tfolderListWidget.folders = folders; // Ensure widget has current folders\n\t\t\t\tfolderListWidget.expandToFolder(folder.id);\n\t\t\t}\n\t\t}\n\n\t\tapp().switchCurrentFolder(folder);\n\t}\n}\n\nmodule.exports = Command;\n","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/laurent22/joplin/blob/2654b33620775080d1d59c552259d41e33dad3d2/packages/app-cli/app/command-use.ts#L4-L40","documentation":"Thrown by the `use` CLI command when app().loadItem(ModelType.Folder, args.notebook) returns null — i.e. no notebook (folder) matches the given name or ID. Once switched, all subsequent CLI operations are scoped to that notebook, so the lookup must succeed.","triggerScenarios":"Running `use <notebook>` where <notebook> matches no folder by name or ID. loadItem resolves against the folder table; a miss returns null and the guard throws.","commonSituations":"Typo in notebook name; the notebook was deleted or renamed; using a notebook ID from a different profile; confusion between a notebook and a tag.","solutions":["List notebooks with `ln` (the folder-list CLI command) to confirm the exact name or ID.","Use the notebook ID instead of its display name.","Check the active profile/database if the notebook is expected to exist.","Sync to pull notebook changes from other clients."],"exampleFix":"// before\nconst folder = await app().loadItem(ModelType.Folder, args['notebook']);\nif (!folder) throw new Error(_('Cannot find \"%s\".', args['notebook']));\n\n// after\nconst folder = await app().loadItem(ModelType.Folder, args['notebook']);\nif (!folder) throw new Error(_('Cannot find notebook \"%s\". Run `ln` to list notebooks.', args['notebook']));","handlingStrategy":"validation","validationCode":"const folder = await Folder.load(notebookNameOrId);\nif (!folder) {\n  console.error(`Notebook \"${notebookNameOrId}\" not found. Run 'ln' to list.`);\n  return;\n}\nawait command.exec(['use', notebookNameOrId]);","typeGuard":"function folderExists(folder: FolderEntity | null): folder is FolderEntity {\n  return folder != null && typeof folder.id === 'string';\n}","tryCatchPattern":"try {\n  await command.exec(['use', notebook]);\n} catch (e) {\n  if (e.message.startsWith('Cannot find')) {\n    // list notebooks and prompt the user to pick\n  } else throw e;\n}","preventionTips":["List notebooks (`ln`) and copy the exact name or ID before calling `use`.","Use IDs rather than display names to avoid rename/encoding issues.","Sync first if notebooks may have changed on other devices."],"tags":["cli","notebook-lookup","validation","user-input"],"backgroundTag":null,"analyzedSha":"2654b33620775080d1d59c552259d41e33dad3d2","analyzedAt":"2026-08-12T14:26:46.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}