Skip to content
@tde.io/plexis  ·  npm install @tde.io/plexis  ·  npm  ·  GitHub

Errors

Plexis throws PlexisError for all runtime errors. It extends the native Error class and carries a typed code field so errors can be handled programmatically.

PlexisError extends Error.

FieldTypeRequiredDescription
codestringYesOne of the error codes below
domainIdstringNoDomain ID, when the error originated in a domain
pipelineIdstringNoPipeline ID, when the error originated in a pipeline
nodeIdstringNoNode ID, when the error is node-specific
contextunknownNoSnapshot of the context at the time of the error
CodeDescription
UNKNOWN_EVENTfollow() was called with an event that has no matching on handler and strict is true
PHASE_MISMATCHfollowFrom() was called but the current phase does not match the expected phase
UNKNOWN_INITIAL_PHASEThe initial ID from the domain setup does not match any registered phase
UNKNOWN_INITIAL_NODEThe initial ID from the pipeline setup does not match any registered node
UNKNOWN_TARGET_PHASEAn event target does not match any registered phase
UNKNOWN_TARGET_NODEA fork target does not match any registered node
UNKNOWN_NODEinspectNode() was called with an ID that does not exist
BUILDER_CLOSEDA registration helper was called outside an active defineDomain or definePipeline setup function
import { defineDomain, when, on, target, terminal } from '@tde.io/plexis';
import type { PlexisError } from '@tde.io/plexis';
const order = defineDomain('order', () => {
when('pending', () => {
on('submit', target('processing'));
});
when('processing', terminal());
return { context: {}, initial: 'pending', strict: true };
});
try {
await order.follow('cancel'); // no 'cancel' event + strict: true
} catch (err) {
const e = err as PlexisError;
if (e.code === 'UNKNOWN_EVENT') {
console.log('No event handler:', e.message);
console.log('Domain:', e.domainId);
}
}
try {
await order.followFrom('processing', 'submit'); // domain is in 'pending'
} catch (err) {
const e = err as PlexisError;
if (e.code === 'PHASE_MISMATCH') {
console.log('Expected phase mismatch:', e.message);
}
}
import { when } from '@tde.io/plexis';
import type { PlexisError } from '@tde.io/plexis';
try {
when('orphan', () => {}); // called outside a setup function
} catch (err) {
const e = err as PlexisError;
console.log(e.code); // 'BUILDER_CLOSED'
}