marklogic-community / marklogic-state-conductor

An event-based state-machine engine for manipulating MarkLogic database documents.
Other
1 stars 4 forks source link

An invalid State Machine file causes the trigger to fail #188

Open aclavio opened 3 years ago

aclavio commented 3 years ago

If a bad state-machine is present in the database, then calls to getAllStateMachinesContextQuery() will cause an exception. This causes the trigger to fail with the following stack trace:

2021-09-22 14:52:37.951 Notice: JS-JAVASCRIPT: const context = domain.context || []; -- Error running JavaScript request: TypeError: Cannot read property 'context' of undefined
2021-09-22 14:52:37.951 Notice:+in /state-conductor/state-conductor.sjs, at 333:25, in getStateMachineContextQuery() [javascript]
2021-09-22 14:52:37.951 Notice:+in /state-conductor/state-conductor.sjs, at 364:27, in getStateMachines.toArray.map() [javascript]
2021-09-22 14:52:37.951 Notice:+in /state-conductor/state-conductor.sjs, at 364:5, in getAllStateMachinesContextQuery() [javascript]
2021-09-22 14:52:37.951 Notice:+in /state-conductor/trigger/state-conductor-item-trigger.sjs, at 22:17, in registerCtxQuery() [javascript]
2021-09-22 14:52:37.951 Notice:+in /state-conductor/trigger/state-conductor-item-trigger.sjs, at 39:20, in getCtxRegQueryId() [javascript]
2021-09-22 14:52:37.951 Notice:+in /state-conductor/trigger/state-conductor-item-trigger.sjs, at 47:22, in checkUriAgainstContext() [javascript]
2021-09-22 14:52:37.951 Notice:+in /state-conductor/trigger/state-conductor-item-trigger.sjs, at 74:4 [javascript]
2021-09-22 14:52:37.951 Notice:+in /state-conductor/trigger/state-conductor-item-trigger.sjs [javascript]

In this case the state-machine didn't contain the required "mlDomain" root level element.

The correct behavior for this scenario is that invalid state-machines are skipped (after logging an error), and no errors bubble up causing the trigger to fail.