Diagnostics
Look up stable diagnostic codes for open, save, edit, review, font, and collaboration failures.
The editor reports open, save, edit, review, font, and collaboration events as diagnostics. This page lists every stable failure code with its cause and action.
Capture diagnostics
Register a module with an onDiagnostic listener when you create the editor:
import { DocxEditor } from '@docx-editor.dev/react';
import { explainDiagnostic, type EditorDiagnostic, type EditorModule } from '@docx-editor.dev/core';
// Create the module once, outside the component. The editor reads modules only at creation.
const diagnostics: EditorModule = {
id: 'diagnostics',
onDiagnostic: (event: EditorDiagnostic) => {
if (event.kind === 'edit.rejected') {
console.warn(event.code, explainDiagnostic(event.code).hint);
}
},
};
const MODULES = [diagnostics];
export function Editor({ bytes }: { bytes: Uint8Array }) {
return <DocxEditor document={bytes} modules={MODULES} />;
}The module receives events from the initial document open. editor.on('diagnostic', listener) receives the same events, but only after the editor exists, so it misses the initial open. A listener that throws does not affect the editor.
Handle a failure code
Branch on code in application logic. These helpers from @docx-editor.dev/core map codes to text:
| Function | Returns |
|---|---|
explainDiagnostic(code) | The fixed hint for a code, and a docs link to its row on this page. |
diagnosticCodeOfRefusal(reason) | The code for the local refusal message in snapshot().lastRejection. |
diagnosticCodes() | Every public code. |
diagnosticCauses() | Every internal cause value. |
In the editing API, a refusal has two codes. error.code says how the call failed. error.debugInfo.innerError.code names the rule from this page. Handle the inner code:
import { isDocxEditorError } from '@docx-editor.dev/editor-api';
try {
await runtime.run(async (context) => {
context.document.body.paragraphs.getFirst().insertText('Reviewed', 'End');
await context.sync();
});
} catch (error) {
if (!isDocxEditorError(error)) throw error;
const rule = error.debugInfo.innerError?.code;
if (rule === 'edit.read-after-commit') {
// The writes are applied. Read again; do not replay them.
} else if (rule === 'edit.stale-target') {
// Read the document again and reconsider the edit.
} else {
throw error;
}
}The outer code for one rule depends on when the runtime refused:
Outer error.code | When |
|---|---|
InvalidArgument | The runtime refused before it wrote anything, such as an unsupported field type or a protected insertion point. A string that is not well-formed XML also gives edit.invalid-argument. |
GeneralException | The document refused the write itself, such as a tracked write into content-locked content with edit.protected-content. |
NotSupported, NotImplemented | The input or operation is outside the supported subset, such as insertOoxml() with more than one equation and edit.ooxml-unsupported. |
Codes are stable. New codes can appear, but existing codes are never renamed. A tracking refusal never justifies switching tracking off automatically to make the edit succeed.
Read diagnostic events
Switch on kind to narrow the event. Every event also has schemaVersion, editorSessionId, and time. The editorSessionId is random per editor instance and is not persisted.
| Kind | When | Fields |
|---|---|---|
document.open | A document opened or failed to open. | outcome (opened or rejected), sizeBucket. Opened: durationMs, pagesBucket (omitted by headless hosts), and shape buckets. Rejected: code and the failure detail. |
document.save | A save() call returned or failed. | outcome (saved or rejected), durationMs. Saved: sizeBucket. Rejected: code and the failure detail. |
edit.rejected | An edit, command, or tracked change was refused. | code, origin (command, input, or automation), tracked, command for a refused exec call, and the failure detail. |
review.skipped | A decision on tracked changes, such as Accept All, skipped some changes. A refused card reports edit.rejected first. In the editing API, only a refused batch reports it (count 1); resolve() returns its skips. | code, count, and the failure detail. |
font.failed | A font did not load; a substitute applies. | code. |
history | An undo step did not group as intended. Informational. | code. |
custom-node | A custom node payload could not be read. | code. The node name is not included. |
collab.status | A collaboration session joined, disconnected, failed, or healed. | status, previous, recovering, and code when something is wrong. The first ready has connectMs when the editor observed the wait. |
collab.participants | The number of people in the room changed. | count, including this editor. |
performance | A timing summary after a minute, on page hide, or on close. | windowMs, optional pagesBucket, interaction, layout, and paint. Slow interactions add code. See Measure performance. |
session | An editor started, was used, or ended. | phase (start, active, or end). active and end add durationMs, activeMs, inputEdits, commandEdits, and automationEdits. See Measure sessions, edits, and saves. |
Sizes and counts use buckets, such as 4-8MiB or 10-99.
Failure detail
Optional detail fields identify the engine condition and where it occurred. They use closed lists.
| Field | On | Holds |
|---|---|---|
cause | document.open, document.save, edit.rejected, review.skipped | The engine's own reason, such as undeclared-prefix under open.xml-malformed. For an unexpected error, exception. |
errorName | document.open, document.save, edit.rejected | The exception class when cause is exception, such as TypeError. The message is never included. |
stage | document.open, document.save, edit.rejected | Where an exception was caught: open-mount, open-layout, command, review-item, automation, or save. |
part | document.open, review.skipped | The package part role, such as main-document, header, or relationships. Nonstandard names report other. |
operation | review.skipped | accept, reject, or reassign. |
changeKind | review.skipped | insert, delete, replace, moveFrom, moveTo, format, paragraphMark, or structural. |
formattingKind | review.skipped | The property change, such as rPrChange or tblGridChange, or other. |
Use code for application logic. Use cause only to investigate, because causes can change between versions.
An open that throws reports open.failed, a save that throws reports save.failed, and a command, review card, or editing API batch that throws reports edit.internal-invariant. Each has cause: 'exception', and the error still reaches your code. An exception from your own code inside run() is not reported.
This event shows a malformed header:
{
"kind": "document.open",
"outcome": "rejected",
"code": "open.xml-malformed",
"cause": "undeclared-prefix",
"part": "header",
"sizeBucket": "64-128KiB"
}When you report a problem, include the code, the failure detail, and the engineVersion that your telemetry adds.
Codes
explainDiagnostic(code).docs links to each code's anchor, such as #edit-read-only.
Open
Limits marked server accept a higher value for a trusted file through the limits option of createServer. The other limits are fixed security refusals.
Save
Edit
Review
Font
The editor substitutes a font for each of these codes.
History
Custom nodes
Performance
| Code | Cause | Action |
|---|---|---|
performance.slow-interaction | More than 1 in 20 key presses or clicks took over 200 ms to paint. | Compare layout (follows document size) and paint (follows pages on screen). |
Collaboration
A collaboration code is collab. plus the session's failure code, on collab.status events. An edit that a session refuses reports edit.rejected with an edit.collaboration-* code instead.
Protect diagnostic data
Engine diagnostics never contain document content. They use closed lists of codes, booleans, and bucketed numbers. Document text, part names, relationship targets, author names, font names, and exception messages are excluded.
Attributes that you add, raw errors, and data your SDK collects can still disclose content. Rare bucket combinations can also distinguish documents within an organization. For more information, see Privacy review checklist.