{"record":{"id":"24b9579f808625b4","repo":"Stirling-Tools/Stirling-PDF","slug":"no-pdf-source-available-for-native-print","errorCode":null,"errorMessage":"No PDF source available for native print","messagePattern":"No PDF source available for native print","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/editor/src/desktop/services/nativePrintService.ts","lineNumber":36,"sourceCode":"    return null;\n  }\n\n  const response = await fetch(url);\n  if (!response.ok) {\n    throw new Error(`Failed to load PDF for native print (${response.status})`);\n  }\n\n  return response.blob();\n}\n\nexport async function printPdfNatively(\n  file?: File | Blob,\n  url?: string | null,\n  fileName = \"document.pdf\",\n) {\n  const source = await resolvePdfSource(file, url);\n  if (!source) {\n    throw new Error(\"No PDF source available for native print\");\n  }\n\n  const { tempDir, join } = await import(\"@tauri-apps/api/path\");\n  const { remove, writeFile } = await import(\"@tauri-apps/plugin-fs\");\n\n  const tempPath = await join(\n    await tempDir(),\n    `stirling-print-${generateId()}-${sanitizeFileName(fileName)}`,\n  );\n\n  await writeFile(tempPath, new Uint8Array(await source.arrayBuffer()));\n\n  try {\n    await invoke(\"print_pdf_file_native\", {\n      filePath: tempPath,\n      title: fileName,\n    });\n  } finally {","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/Stirling-Tools/Stirling-PDF/blob/9ef20dcab80b85041912f045e17a6aea1d08f969/frontend/editor/src/desktop/services/nativePrintService.ts#L18-L54","documentation":"Thrown by printPdfNatively when resolvePdfSource() returns null — neither a File/Blob nor a url was supplied, so there is no PDF to print. This is a programmer/contract error, not a runtime/network one: every caller must provide at least one source.","triggerScenarios":"Calling printPdfNatively() (or with both file and url undefined/null): a code path that lost the reference to the PDF before invoking print, or a state where the file was cleared but the print action still fired.","commonSituations":"FileContext cleared the active file (e.g. user navigated away) but the print button handler ran with a stale closure; a tool produced no output and the print action fired anyway.","solutions":["Ensure the caller always passes a non-null File/Blob (preferred) or a valid url to printPdfNatively.","Guard the print action on the UI side: disable it until a PDF source is available.","Pass the blob directly from the tool result instead of relying on a url that may be cleared."],"exampleFix":"// before\nawait printPdfNatively(activeFile ?? undefined, activeUrl);\n\n// after: guarantee a source exists before printing\nif (!activeFile && !activeUrl) { notify('Open a PDF first.'); return; }\nawait printPdfNatively(activeFile ?? undefined, activeUrl ?? null);","handlingStrategy":"validation","validationCode":"if (!file && !url) { notify('Open a PDF first.'); return; }\nawait printPdfNatively(file ?? undefined, url ?? null, fileName);","typeGuard":"function isNoPrintSource(e: unknown): e is Error {\n  return e instanceof Error && e.message === 'No PDF source available for native print';\n}","tryCatchPattern":"try { await printPdfNatively(file ?? undefined, url ?? null, fileName); }\ncatch (e) {\n  if (isNoPrintSource(e)) { notify('Open a PDF first.'); return; }\n  throw e;\n}","preventionTips":["Always pass at least one source to printPdfNatively.","Disable the print action until a PDF is loaded.","Avoid relying on a url that may have been revoked."],"tags":["print","pdf","validation","desktop"],"backgroundTag":null,"analyzedSha":"9ef20dcab80b85041912f045e17a6aea1d08f969","analyzedAt":"2026-08-13T22:11:39.827Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}