{"record":{"id":"1a6085ad289fa4bf","repo":"hcengineering/platform","slug":"failed-to-create-pdf-err-message","errorCode":null,"errorMessage":"Failed to create PDF: ${err.message}","messagePattern":"Failed to create PDF: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pods/preview/src/utils/libreoffice.ts","lineNumber":92,"sourceCode":"          reject(new Error(`LibreOffice exited with code ${code}`))\n        } else {\n          resolve()\n        }\n      })\n\n      proc.on('error', (err) => {\n        ctx.error('LibreOffice failed', { stdout, stderr, docFile, pdfFile })\n        reject(new Error(`Failed to start LibreOffice: ${err.message}`))\n      })\n    })\n  } finally {\n    await rm(profileDir, { recursive: true })\n  }\n\n  try {\n    await access(pdfFile)\n  } catch (err: any) {\n    throw new Error(`Failed to create PDF: ${err.message}`)\n  }\n\n  return pdfFile\n}\n","sourceCodeStart":74,"sourceCodeEnd":97,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/pods/preview/src/utils/libreoffice.ts#L74-L97","documentation":"docToPdf converts office documents to PDF using LibreOffice (soffice) with a temporary profile directory. After running the conversion it verifies the expected output file exists via fs access; if the PDF was not produced it throws this error with LibreOffice's stderr/err.message appended. It signals the office-to-PDF conversion pipeline failed.","triggerScenarios":"Converting a doc/docx/odt (or similar) blob to PDF when soffice is missing, crashes, times out, or rejects the input file — so the output .pdf never appears on disk.","commonSituations":"Host without LibreOffice installed, HOME/profile-dir permission problems for the soffice process, password-protected or corrupt documents, resource exhaustion (memory/CPU) killing soffice, unsupported legacy formats.","solutions":["Verify LibreOffice (soffice) is installed and executable on the host and works headless (soffice --headless --convert-to pdf test.docx).","Check the wrapped err.message/LibreOffice stderr for the specific conversion failure (corrupt file, unsupported format, permissions).","Test the specific document manually with the same soffice command; re-export/re-upload the file if it is corrupt.","Check permissions on the temp/profile directories and available disk space and memory."],"exampleFix":"// before\nconst pdfFile = await docToPdf(ctx, inputDocPath)\n// after\nif (!existsSync(inputDocPath) || statSync(inputDocPath).size === 0) {\n  throw new Error('source document missing or empty')\n}\nconst pdfFile = await docToPdf(ctx, inputDocPath)","handlingStrategy":"validation","validationCode":"import { access, constants } from 'fs/promises'\nawait access(inputDocPath, constants.R_OK) // source must exist and be readable\nif (statSync(inputDocPath).size === 0) throw new Error('empty document')","typeGuard":"function isConvertibleDoc(contentType: string): boolean {\n  return /msword|openxmlformats|opendocument/.test(contentType)\n}","tryCatchPattern":"try {\n  const pdf = await docToPdf(ctx, docPath)\n} catch (err) {\n  if (/Failed to create PDF/.test(err.message)) {\n    ctx.error('libreoffice conversion failed', { cause: err.message, docPath })\n    throw new Error('document conversion unavailable')\n  }\n  throw err\n}","preventionTips":["Install and smoke-test LibreOffice headless in the deployment image.","Check soffice profile dir permissions and HOME for the service user.","Validate uploaded documents before conversion.","Ensure enough memory/disk for soffice child processes."],"tags":["libreoffice","soffice","pdf","document-conversion"],"backgroundTag":"libreoffice-conversion-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}