Error handling and diagnostics
Read diagnostics and handle failures. Code examples in the DocStudio developer reference.
Diagnostics
Every core function reports problems as diagnostics instead of throwing. A diagnostic has a code, a severity (error or warning), a message and a JSON Pointer path.
Rules of thumb
- Check
result.okor the presence ofresult.treebefore using a compile result. - Treat
errordiagnostics as failures andwarningdiagnostics as information to log. - Use
pathto find the node: the pointer starts at the template, for example/body/0/content/1. - Do not parse messages. Messages are for people, codes are stable.
Other failure shapes
| API | Failure |
|---|---|
compile, render |
diagnostics array, never an exception |
| PDF client and service | { ok: false, status, diagnostics } |
| Storage ports | { ok: false, code, message } |
| Editor commands | { ok: false, reason, diagnostics } and the state does not change |
| Host HTTP handler | A status code and { ok: false, error: { code, message } } with fixed text |
Every diagnostic code is listed in Diagnostics.