Bug
I've been messing around with xstate and working out how to build parallel and hierarchical state machines. I've made a contrived state machine as a sort of working example for a project I'm working on. I then run through the states in the machine, using setTimeout and console.log-ing as the state changes.
This worked fine with the previous version of xstate that I was using - v.3.2.1 . Yesterday I updated to v3.3.1, and now running my machine I get the following error:
Not to get any errors (or only ones that can be traced to my code).
/home/jo/dev/joState/stateMachine/node_modules/xstate/lib/utils.js:103
var result = exports.flatMap(Object.keys(stateValue).map(function (key) {
^
TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at Object.exports.toStatePaths (/home/jo/dev/joState/stateMachine/node_modules/xstate/lib/utils.js:103:41)
at /home/jo/dev/joState/stateMachine/node_modules/xstate/lib/utils.js:104:24
at Array.map (<anonymous>)
at Object.exports.toStatePaths (/home/jo/dev/joState/stateMachine/node_modules/xstate/lib/utils.js:103:58)
at /home/jo/dev/joState/stateMachine/node_modules/xstate/lib/utils.js:104:24
at Array.map (<anonymous>)
at Object.exports.toStatePaths (/home/jo/dev/joState/stateMachine/node_modules/xstate/lib/utils.js:103:58)
at StateNode._transitionOrthogonalNode (/home/jo/dev/joState/stateMachine/node_modules/xstate/lib/StateNode.js:234:28)
at StateNode._transition (/home/jo/dev/joState/stateMachine/node_modules/xstate/lib/StateNode.js:248:21)
I've tried to debug my own code to see if there's a problem there, but I really can't find anything that would cause an error. I'm aware of some flaws in how I'm implementing my machine, but those are design flaws rather than breaking code.
Really enjoying the library by the way, and the visualiser is a great addition. Thanks for working on this :)
Additionally, I went into the xstate directory in node_modules, so that I could run the unit tests and mess around trying to find bugs in my code.
On running npm i there, I get:
src/scxml.ts:195:47 - error TS2345: Argument of type 'string | number | undefined' is not assignable to parameter of type 'string | number'.
Type 'undefined' is not assignable to type 'string | number'.
195 transition.actions.push(actions.raise(element.attributes!.event));
~~~~~~~~~~~~~~~~~~~~~~~~~
src/scxml.ts:293:36 - error TS2345: Argument of type 'string | number | undefined' is not assignable to parameter of type 'string | number'.
Type 'undefined' is not assignable to type 'string | number'.
293 return actions.raise(element.attributes!.event);
~~~~~~~~~~~~~~~~~~~~~~~~~
src/scxml.ts:304:36 - error TS2345: Argument of type 'string | number | undefined' is not assignable to parameter of type 'string | number'.
Type 'undefined' is not assignable to type 'string | number'.
304 return actions.raise(element.attributes!.event);
~~~~~~~~~~~~~~~~~~~~~~~~~
src/scxml.ts:343:31 - error TS2339: Property 'elements' does not exist on type 'ElementCompact | Element'.
Property 'elements' does not exist on type 'ElementCompact'.
343 const machineElement = json.elements.filter(
~~~~~~~~
Hi! I just took a quick look at the repo you linked and I'm reproducing it in my debugger. If you open the chrome debugger, you can catch the debugger when it throws the exception and start poking around.
The call stack is something like:
transition → transitionHierarchcialNode → Transition → TransitionOrthogonalNode → allPaths → anonymous → allPaths → anonymous → allPaths()
The transitionOrthogonalNode calls allPaths with the value
{
dependenciesResolving: {
magpie: "inProgress",
morrigu: undefined
}
}
The machine itself, before that transition is in the state
{"dependenciesResolving": {
"magpie": "inProgress",
"morrigu": {
"dependenciesResolving": {
"searchlens": "pending",
"googleAnalytics": "pending"
}
}
}
}
morrigu is the name of the region which wants to transition between states. Hope this helps @davidkpiano
You can ignore scxml.ts - it's not used in the core library.
Additionally, can you please reproduce your code to a minimal test case? It's a bit difficult to debug as-is.
Thanks; yes I'll try to simplify the machine and see if I can still reproduce the error.
I'd managed to get to morrigu: undefined (via a different route)... I'm just not sure _why_ it's undefined.
I'll keep digging.
Awesome - 3.3.2 fixes my issue. And @mogsie your debugger is very useful.
Thank you both!
Most helpful comment
Awesome - 3.3.2 fixes my issue. And @mogsie your debugger is very useful.
Thank you both!