Stirling-Tools/Stirling-PDF · error · Error
No PDF source available for native print
Error message
No PDF source available for native print
What it means
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.
Source
Thrown at frontend/editor/src/desktop/services/nativePrintService.ts:36
return null;
}
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Failed to load PDF for native print (${response.status})`);
}
return response.blob();
}
export async function printPdfNatively(
file?: File | Blob,
url?: string | null,
fileName = "document.pdf",
) {
const source = await resolvePdfSource(file, url);
if (!source) {
throw new Error("No PDF source available for native print");
}
const { tempDir, join } = await import("@tauri-apps/api/path");
const { remove, writeFile } = await import("@tauri-apps/plugin-fs");
const tempPath = await join(
await tempDir(),
`stirling-print-${generateId()}-${sanitizeFileName(fileName)}`,
);
await writeFile(tempPath, new Uint8Array(await source.arrayBuffer()));
try {
await invoke("print_pdf_file_native", {
filePath: tempPath,
title: fileName,
});
} finally {View on GitHub (pinned to 9ef20dcab8)
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.
Example fix
// before
await printPdfNatively(activeFile ?? undefined, activeUrl);
// after: guarantee a source exists before printing
if (!activeFile && !activeUrl) { notify('Open a PDF first.'); return; }
await printPdfNatively(activeFile ?? undefined, activeUrl ?? null); Defensive patterns
Strategy: validation
Validate before calling
if (!file && !url) { notify('Open a PDF first.'); return; }
await printPdfNatively(file ?? undefined, url ?? null, fileName); Type guard
function isNoPrintSource(e: unknown): e is Error {
return e instanceof Error && e.message === 'No PDF source available for native print';
} Try / catch
try { await printPdfNatively(file ?? undefined, url ?? null, fileName); }
catch (e) {
if (isNoPrintSource(e)) { notify('Open a PDF first.'); return; }
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to load PDF for native print (${response.status})
- File ${file.name} appears to be corrupted
- No pages to export
- No team resolved yet
- No automation configuration provided
AI-assisted analysis of Stirling-Tools/Stirling-PDF@9ef20dcab8 (2026-08-13).
Data as JSON: /api/errors/24b9579f808625b4.
Report an issue: GitHub.