Errors and safeguards

Copy Markdown View Source

Nothing a model writes may crash the host (language.md, section 10). A mistake removes the smallest unit it touches, everything else renders, and every removal is reported.

Error codes

CodeSourceWhenWhat happens
unknown-componentparserComponent not in the catalogLeft out; in a list, the :unknown slot shows in its place
missing-requiredparserA required prop is absentIts default fills it, or the component is dropped
null-requiredparserA required prop is nullSame as above
type-mismatchparserA value does not fit the prop's type or enumThe default, or the optional prop or list item is removed; a required prop drops the component
excess-argsparserMore arguments than propsExtra arguments are dropped
inline-reservedparserQuery or Mutation used inside an expressionThat expression is left out
unknown-functionparser@Name that does not existThe call is null; the statement stays
no-rootparser, runtimeNo usable entry statementA warning when a fallback entry renders; nothing renders otherwise
parse-failedparserText with no statementsNothing renders
parse-exceptionparserThe parser itself failedNothing renders; caught, never raised
runtime-errorruntimeA function raised or got bad arguments; a component raised while renderingThe value is null; the component is left out
tool-not-foundquery, mutationThe tool does not existThe query keeps its defaults; the hint lists the tools
tool-errorquery, mutationThe tool failed or raisedThe query keeps its last data; a mutation reports the error and stops its action

The error object

OpenUI.Error.to_map/1 gives the wire shape of language.md, section 8.3, ready to send to the model:

{"source": "parser", "code": "missing-required", "statementId": "chart", "component": "Metric",
 "path": "/value", "message": "missing required field \"/value\"", "hint": "Signature: Metric(label*, value*). * marks required"}

The renderer reports the list only when it changes, and [] once it recovers. While a stream is open nothing is reported: a half-written program is not an error.

The four protections of the LiveView renderer

  1. Program mistakes follow the table above.
  2. Unknown components render the :unknown slot, or nothing.
  3. Host components that raise. Each component renders once inside a rescue. One that raises is left out, reported as runtime-error with its statement, and logged with its stacktrace. The rest of the page renders.
  4. Failures of the renderer itself, such as a broken components module, leave the program empty and are logged. The page stays up.

Text cut in the middle

A stream can stop anywhere, even inside a multibyte character. The stream holds those bytes until the rest arrives; text that is still cut when parsed shows U+FFFD in place of the stray bytes. Data from tools gets the same treatment.

Logging

Protections 3 and 4 log with Logger.error, including the component and the stacktrace, so a bug in your components shows up in your error tracker while the person sees the rest of the answer.