{"record":{"id":"60d4cfa3fe855cbd","repo":"laurent22/joplin","slug":"only-one-note-can-be-printed-at-a-time","errorCode":null,"errorMessage":"Only one note can be printed at a time.","messagePattern":"Only one note can be printed at a time\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/app-desktop/gui/WindowCommandsAndDialogs/commands/print.ts","lineNumber":18,"sourceCode":"import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';\nimport { _ } from '@joplin/lib/locale';\nimport { WindowControl } from '../utils/useWindowControl';\nimport bridge from '../../../services/bridge';\n\nexport const declaration: CommandDeclaration = {\n\tname: 'print',\n\tlabel: () => _('Print'),\n\ticonName: 'fa-file',\n};\n\nexport const runtime = (comp: WindowControl): CommandRuntime => {\n\treturn {\n\t\texecute: async (context: CommandContext, noteIds: string[] = null) => {\n\t\t\tnoteIds = noteIds || context.state.selectedNoteIds;\n\n\t\t\ttry {\n\t\t\t\tif (noteIds.length !== 1) throw new Error(_('Only one note can be printed at a time.'));\n\t\t\t\tawait comp.printTo('printer', { noteId: noteIds[0] });\n\t\t\t} catch (error) {\n\t\t\t\tbridge().showErrorMessageBox(error.message);\n\t\t\t}\n\t\t},\n\t\tenabledCondition: 'someNotesSelected && !noteLockContentUnavailable',\n\t};\n};\n","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/laurent22/joplin/blob/2654b33620775080d1d59c552259d41e33dad3d2/packages/app-desktop/gui/WindowCommandsAndDialogs/commands/print.ts#L1-L27","documentation":"Thrown by the print command when noteIds.length is not exactly 1. The renderer's printTo accepts a single noteId; printing zero or multiple notes at once is unsupported.","triggerScenarios":"Executing print with an empty selection (length 0) or a multi-selection (length > 1). The guard `if (noteIds.length !== 1)` fires before comp.printTo.","commonSituations":"User triggers Print with no note selected; user multi-selects notes and hits Print; a plugin calls execute() without filtering to a single note.","solutions":["Select exactly one note before printing.","Gate the command behind an enabledCondition of `oneNoteSelected` (currently it uses someNotesSelected).","If invoking programmatically, pass a single-element noteIds array.","Loop and print one at a time if batch printing is genuinely needed."],"exampleFix":"// before\nif (noteIds.length !== 1) throw new Error(_('Only one note can be printed at a time.'));\n\n// after — clear guidance in the message\nif (noteIds.length !== 1) {\n  throw new Error(_('Only one note can be printed at a time. %d note(s) selected.', noteIds.length));\n}","handlingStrategy":"validation","validationCode":"if (!noteIds || noteIds.length !== 1) {\n  // prompt user to select exactly one note\n  return;\n}\nawait CommandService.instance().execute('print', noteIds);","typeGuard":"function exactlyOneNote(ids: string[] | null | undefined): ids is [string] {\n  return Array.isArray(ids) && ids.length === 1;\n}","tryCatchPattern":"try {\n  await CommandService.instance().execute('print', noteIds);\n} catch (e) {\n  if (e.message.includes('Only one note can be printed')) {\n    // tell the user to select a single note\n  } else throw e;\n}","preventionTips":["Use an enabledCondition of 'oneNoteSelected' for the print command.","Pass a single-element array when invoking programmatically.","For batch needs, loop and print one note at a time."],"tags":["desktop","print","validation","selection"],"backgroundTag":null,"analyzedSha":"2654b33620775080d1d59c552259d41e33dad3d2","analyzedAt":"2026-08-12T14:26:46.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}