{"record":{"id":"130ae76ca3b6251e","repo":"hcengineering/platform","slug":"failed-to-get-metadata-err-message-130ae7","errorCode":null,"errorMessage":"Failed to get metadata: ${err.message}","messagePattern":"Failed to get metadata: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pods/preview/src/providers/pdf.ts","lineNumber":77,"sourceCode":"\n    return { mimeType: 'image/png', filePath: pngFile }\n  }\n\n  async metadata (\n    ctx: MeasureContext,\n    workspace: WorkspaceUuid,\n    name: string,\n    contentType: string\n  ): Promise<PreviewMetadata> {\n    const { filePath: path } = await ctx.with('thumbnail', {}, (ctx) => {\n      return this.image(ctx, workspace, name, contentType)\n    })\n\n    try {\n      const thumbnail = await getImageMetadata(ctx, path)\n      return { thumbnail }\n    } catch (err: any) {\n      throw new Error(`Failed to get metadata: ${err.message}`)\n    } finally {\n      this.tempDir.rm(path)\n    }\n  }\n}\n","sourceCodeStart":59,"sourceCodeEnd":83,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/pods/preview/src/providers/pdf.ts#L59-L83","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst thumbnail = await getImageMetadata(ctx, path)\n// after\ntry {\n  const thumbnail = await getImageMetadata(ctx, path)\n} catch (err) {\n  ctx.error('metadata failed on rendered png', { err, path })\n  throw err\n}","handlingStrategy":"try-catch","validationCode":"const stat = await storage.stat(ctx, { uuid: workspace }, name)\nif (stat === undefined || !stat.contentType.startsWith('application/pdf')) return null","typeGuard":"function isPdfBlob(stat): stat is Blob {\n  return stat != null && typeof stat.contentType === 'string' && stat.contentType.startsWith('application/pdf')\n}","tryCatchPattern":"try {\n  const meta = await preview.metadata(ctx, workspace, name)\n} catch (err) {\n  if (String(err.message).startsWith('Failed to get metadata:')) {\n    ctx.warn('pdf preview metadata unavailable', { name, cause: err.message })\n    return { thumbnail: undefined }\n  }\n  throw err\n}","preventionTips":["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."],"tags":["preview","pdf","image-processing","sharp"],"backgroundTag":"image-metadata-extraction-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}