typegen: exit 0 on error
Currently, the typegen exits with 0 when the input file, or any of the input files, has an error.
Because of this, it's hard to surface issues with the machine you are working with when using the typegen as a file watcher run when saving on Webstorm (or other similar IDEs). This is because Webstorm shows the output of the watcher command only in case of errors.
An exit code 1 would enable Webstorm to do the right thing.
Proof of exit 0:
~/Code/app-services-ui-components sizes-can-be-unavailable*
❯ /opt/homebrew/bin/xstate typegen src/Kafka/CreateKafkaInstanceWithSizes/CreateKafkaInstanceMachine.ts
Error: Invalid transition definition for state node 'createKafkaInstance.standardPlan.saving':
Child state 'complete' does not exist on 'createKafkaInstance.standardPlan'
at /opt/homebrew/lib/node_modules/@xstate/cli/node_modules/xstate/lib/StateNode.js:1449:17
at Array.map (<anonymous>)
at StateNode.resolveTarget (/opt/homebrew/lib/node_modules/@xstate/cli/node_modules/xstate/lib/StateNode.js:1429:20)
at StateNode.formatTransition (/opt/homebrew/lib/node_modules/@xstate/cli/node_modules/xstate/lib/StateNode.js:1465:23)
at /opt/homebrew/lib/node_modules/@xstate/cli/node_modules/xstate/lib/StateNode.js:1543:22
at Array.map (<anonymous>)
at /opt/homebrew/lib/node_modules/@xstate/cli/node_modules/xstate/lib/StateNode.js:1542:46
at Array.map (<anonymous>)
at StateNode.formatTransitions (/opt/homebrew/lib/node_modules/@xstate/cli/node_modules/xstate/lib/StateNode.js:1541:278)
at StateNode.get (/opt/homebrew/lib/node_modules/@xstate/cli/node_modules/xstate/lib/StateNode.js:320:75)
src/Kafka/CreateKafkaInstanceWithSizes/CreateKafkaInstanceMachine.ts - success
~/Code/app-services-ui-components sizes-can-be-unavailable*
❯ echo $?
0
Sample Webstorm watcher config:

If I understand correctly you are using here WebStorm watcher and not the @xstate/cli watch, right? Which version of the CLI are you using? This issue was supposed to be fixed some time ago:
https://github.com/statelyai/xstate-tools/blob/9d82f5cd6d21fd5a93eb4b0de5f5f706f1b8a2b3/apps/cli/src/bin.ts#L130-L132
Could you create a minimal repro case?
That's correct, I'm calling typegen directly and not using its watch mode.
I'll check tomorrow the version, but I installed the cli yesterday and I'm sure it was the first time ever since I had to xstate command in my path before doing that.
Here is the version:
❯ xstate --version
0.1.7
~
❯ which xstate
/opt/homebrew/bin/xstate
It's the latest according to npmjs
~/
❯ xstate typegen test.ts
Error: Invalid transition definition for state node '(machine).test':
Child state 'foozz' does not exist on '(machine)'
at /Users/riccardoforina/Library/Application Support/fnm/node-versions/v16.15.0/installation/lib/node_modules/@xstate/cli/node_modules/xstate/lib/StateNode.js:1449:17
at Array.map (<anonymous>)
at StateNode.resolveTarget (/Users/riccardoforina/Library/Application Support/fnm/node-versions/v16.15.0/installation/lib/node_modules/@xstate/cli/node_modules/xstate/lib/StateNode.js:1429:20)
at StateNode.formatTransition (/Users/riccardoforina/Library/Application Support/fnm/node-versions/v16.15.0/installation/lib/node_modules/@xstate/cli/node_modules/xstate/lib/StateNode.js:1465:23)
at /Users/riccardoforina/Library/Application Support/fnm/node-versions/v16.15.0/installation/lib/node_modules/@xstate/cli/node_modules/xstate/lib/StateNode.js:1543:22
at Array.map (<anonymous>)
at /Users/riccardoforina/Library/Application Support/fnm/node-versions/v16.15.0/installation/lib/node_modules/@xstate/cli/node_modules/xstate/lib/StateNode.js:1542:46
at Array.map (<anonymous>)
at StateNode.formatTransitions (/Users/riccardoforina/Library/Application Support/fnm/node-versions/v16.15.0/installation/lib/node_modules/@xstate/cli/node_modules/xstate/lib/StateNode.js:1541:278)
at StateNode.get (/Users/riccardoforina/Library/Application Support/fnm/node-versions/v16.15.0/installation/lib/node_modules/@xstate/cli/node_modules/xstate/lib/StateNode.js:320:75)
src/Kafka/CreateKafkaInstanceWithSizes/test.ts - success
~/
❯ echo $?
0