Diagnostics and error handling

How DocStudio reports problems: diagnostics with code, severity, message and JSON Pointer path instead of exceptions, plus limits and typed results.

DocStudio's public functions are designed not to throw for template or data problems. They return diagnostics.

The diagnostic shape

interface Diagnostic {
  code: string;
  severity: 'error' | 'warning';
  message: string;
  path: string;
}

path is a JSON Pointer into the template, for example /body/2/columns/1/header. Common codes include SCHEMA_VIOLATION, SCOPE_VIOLATION, MISSING_DATA, WRONG_TYPE and LIMIT_EXCEEDED. The full list is DIAGNOSTIC_CODES in docstudio/core.

Where they appear

  • compile returns { ok, tree, diagnostics, meta, trace }.
  • renderDocument returns { ok, html, diagnostics }.
  • render returns diagnostics next to its HTML.
  • The PDF service and client return { ok: false, diagnostics } when a job fails.
  • The designer lists them in the Problems tab.

Handling them

const result = renderDocument(template, data);
if (!result.ok) {
  for (const item of result.diagnostics) console.error(item.code, item.path, item.message);
}

Warnings do not set ok to false. With missingData: 'error', missing data becomes an error.

Limits

Resource limits bound template size, node count, repeater rows, image size, composite nesting and compile time. Exceeding one is a LIMIT_EXCEEDED diagnostic. Lower them with normalizeLimits from docstudio/core.

Traces

compile can record a trace of how values were bound. Traces contain data previews, so treat them as sensitive and do not log them.

Last updated 2026-12-03