hcengineering/platform · error
Failed to get metadata: ${err.message}
Error message
Failed to get metadata: ${err.message} What it means
The PDF preview provider's metadata() first renders the PDF to a PNG via pdfToImage, then calls getImageMetadata (sharp) to read dimensions of the generated image. This error wraps any failure of that metadata read, e.g. the rendered PNG is missing, empty, corrupted, or sharp cannot parse it. The original cause is preserved in err.message appended to the message.
Source
Thrown at pods/preview/src/providers/pdf.ts:77
return { mimeType: 'image/png', filePath: pngFile }
}
async metadata (
ctx: MeasureContext,
workspace: WorkspaceUuid,
name: string,
contentType: string
): Promise<PreviewMetadata> {
const { filePath: path } = await ctx.with('thumbnail', {}, (ctx) => {
return this.image(ctx, workspace, name, contentType)
})
try {
const thumbnail = await getImageMetadata(ctx, path)
return { thumbnail }
} catch (err: any) {
throw new Error(`Failed to get metadata: ${err.message}`)
} finally {
this.tempDir.rm(path)
}
}
}
View on GitHub (pinned to 63e28dc964)
Solutions
- Read the wrapped err.message in logs to find the root cause (missing file vs. unsupported/corrupt image).
- Install/verify the PDF rendering toolchain (poppler-utils/ghostscript) on the preview service host so pdfToImage produces a valid PNG.
- Retry metadata; if the PDF is corrupted or encrypted, re-upload a valid file.
- Check free disk space and temp-dir permissions under the service's TemporaryDir.
Example fix
// before
const thumbnail = await getImageMetadata(ctx, path)
// after
try {
const thumbnail = await getImageMetadata(ctx, path)
} catch (err) {
ctx.error('metadata failed on rendered png', { err, path })
throw err
} Defensive patterns
Strategy: try-catch
Validate before calling
const stat = await storage.stat(ctx, { uuid: workspace }, name)
if (stat === undefined || !stat.contentType.startsWith('application/pdf')) return null Type guard
function isPdfBlob(stat): stat is Blob {
return stat != null && typeof stat.contentType === 'string' && stat.contentType.startsWith('application/pdf')
} Try / catch
try {
const meta = await preview.metadata(ctx, workspace, name)
} catch (err) {
if (String(err.message).startsWith('Failed to get metadata:')) {
ctx.warn('pdf preview metadata unavailable', { name, cause: err.message })
return { thumbnail: undefined }
}
throw err
} Prevention
- Ensure poppler/ghostscript are present in the preview image and verified in CI.
- Validate PDFs (page count > 0, not encrypted) at upload time.
- Monitor disk space for the temp directory.
- Log the wrapped cause message for triage.
When it happens
Trigger: Calling the preview service metadata endpoint for a blob with contentType application/pdf where pdfToImage produced an invalid/empty PNG (corrupted or password-protected PDF, missing poppler/gs tooling), or the temp file was removed before sharp read it.
Common situations: PDFs with zero pages, encrypted PDFs, hosts without pdftoppm/ghostscript installed, disk-full so the temp PNG is truncated, stale temp-dir cleanup racing the read.
Related errors
- Failed to get metadata: ${err.message}
- Failed to get metadata: ${err.message}
- Failed to get metadata: ${err.message}
- Not Found
- Unsupported content type: ${contentType}
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/130ae76ca3b6251e.
Report an issue: GitHub.