Error handling
An authoring verb that gets rejected, either by the engine or by the SDK itself before any
round-trip, throws AuthoringError. It carries everything you need to recover, in author
vocabulary.
The fields and reason values are in the AuthoringError reference.
Fail-closed by design
Section titled “Fail-closed by design”A failed run writes nothing. Verbs only schedule directives against the engine’s staging
tree; disk writes happen at Commit, after your factory returns. A thrown
AuthoringError (or any error) before return therefore leaves the target project exactly as it was.
There is no partial-write state to clean up, which is why the verbs themselves are strict:
create rejects an existing path, replaceContent rejects a missing one, and overwrites
require an explicit { force: true }. See
Mutation verbs for each verb’s exact semantics.
Catching and recovering
Section titled “Catching and recovering”Switch on reason to handle each rejection. Calling the runner directly throws, while
runFactoryForTest captures the same AuthoringError on result.error (see the
testing guide). Every reason value has a case here; the
AuthoringError reference describes each one:
switch (err.reason) { case "path-collision": console.error(`${err.verb} collided at ${err.path}`); break; case "path-not-found": case "unrepresentable-content": case "changes-too-large": case "outside-session": case "unknown": case "invalid-input": case "reserved-name": case "source-not-found": case "source-not-regular-file": case "source-unreadable": console.error(err.message); break;}Writing good failure paths
Section titled “Writing good failure paths”Write factories that treat rejection as an expected outcome:
- Prevent
path-collisionby reading first. The most common rejection is a re-run hitting a file the previous run created. Branch onfind().read()’s trichotomy (create when absent, update when present) instead of reaching for{ force: true }, which turns every re-run into a silent overwrite. - Pass
force: trueonly when overwriting is the intent. Fail-closed collisions are the SDK protecting earlier output; forcing them away removes that protection for this run and every future one. - Let unexpected states fail loud. A rejected run discards everything and leaves the tree untouched, so throwing is always safe. A factory that detects a state it doesn’t understand should throw rather than guess.
- Switch exhaustively on
reason. The closed union means the compiler tells you when a new SDK version adds (or removes) a rejection cause, as thesource-outside-packageremoval described in the reference shows. - In tests, assert on the structured fields.
result.error.verb,.path, and.reasonpin down which directive failed and why, which makes them far more mutation-resistant than matching onmessagetext. Remember the"modify"label quirk when the failing call is areplaceContent.
Next steps
Section titled “Next steps”AuthoringErrorreference: fields,reasonvalues, and how errors surface.- Mutation verbs: the seven authoring verbs and the read-trichotomy rule.
- Pending directives: preview a factory’s planned changes before anything commits.