Skip to Content
PackagesCoreDiagnostics

Diagnostics

Things go wrong in a live editor: a cross-reference loses its target, a plugin throws, a node view crashes, the layout check fails. Each of them is reported through one callback, onDiagnostic, on the mount config:

import type { DiagnosticCallback } from "@stesura/core/types"; const onDiagnostic: DiagnosticCallback = (diagnostic) => { switch (diagnostic.type) { case "reference-missing": flagBrokenReference(diagnostic.targetId); break; case "dispatch-error": case "node-view-crash": sendToTelemetry(diagnostic.error); break; } }; const editor = useLocalEditor({ editorId, configuration: { config: { onDiagnostic } }, });

Every diagnostic carries type and editorId, the mount it was raised in. Diagnostics raised inside a sub-editor (a footnote, a header) reach the root mount’s callback with the sub-editor’s own id. A callback that throws is caught and logged, so it never breaks an edit.

typePayloadWhen
reference-missingtargetIdA cross-reference now points at an id the document doesn’t have (the target was deleted or hidden). Once per target. A reference already broken in the loaded document is reported on the first pass after mount.
reference-restoredtargetIdA target reported missing is back (undo, reveal, or an id coming back), so its references resolve again. Deleting the broken reference itself is not a restore.
dispatch-errorerrorA transaction threw while being applied. It was dropped and the user got a dispatchFailed toast.
node-view-crashnodeType, errorA node view threw while rendering and now shows a placeholder.
pagination-failurereportA layout check failed, recovered or gave up. See Layout failures.
doc-integrityreportA broken section structure was repaired on load, or an edit that would break it was refused. report.doc is the document as found.

The narrower channels still fire alongside it: addPaginationFailureHandler from @stesura/pagination and addDocIntegrityHandler from @stesura/core/helpers are process-wide, so they suit telemetry set up once per page. Messages for the user still go through onToast; onDiagnostic is for the host.

Reporting your own

reportDiagnostic from @stesura/core/helpers routes a diagnostic to the mount registered under its editorId, or through the EditorState you pass:

import { reportDiagnostic } from "@stesura/core/helpers"; reportDiagnostic({ type: "node-view-crash", editorId, nodeType: "chart", error }, view.state);
Last updated on