Thanks for that pointer @saul. Documentation useful to script writers seems scarce.
If reading the example script documentation closely, please note that some exit code documentation from that script is not in beta just yet (only in canary). See Improvements for –run-script-before/after options for history and some other links to scripting information.