Handling exceptions in setWatch/setInterval

Posted on
  • It's been a longstanding annoyance for me that you can do something like:

    function test() {

    and can generate a whole stream of exceptions on the console. It's not a big deal for USB-connected devices, but for Puck.js printing that amount of data swamps everything else.

    Generally this doesn't happen too much, but if you're changing code using the REPL and you make a typo in a function called from an interval then it's really annoying.

    At the moment, if you hit Ctrl-C a few times generally you can get it to cancel the interval with the error, but it's still a pain.

    Node.js cancels an interval the very first time there's an exception, but personally I don't think you want that because you might have some code in production that fails one in 100 times, but you want it to keep running regardless.

    Any thoughts on how to deal with this?

    • Espruino could detect exceptions and cancel the interval if there were 3 exceptions one after the other with no successfully completed one?
    • We could keep executing, but not report an exception if it was identical to the last one.
    • By default we could do what node.js does and kill any intervals that throw exceptions, and there could be an option to stop that behaviour. However I think 99.9% of people would keep the default behaviour, which would then make Espruino less reliable in production.
  • I'm thinking about adding something like error number since started. If you can detect that it is the same error/exception, then just printing the new error number with the number of first occurrence. Since the numbers is incrementing you also get a *feel of 'distance' between same errors. Using some kind of a threshold - general or per individual interval (id) when specified - and the error occurrence could trigger an event with context information (interval id? and) what is suitable and let the app handle it the application overrides a default behavior, which would be killing specific/all interval/s. (Is that a similar issue pattern you find in the browser when the user gets presented the option to choose/confirm Don't show this alert/message pop-up anymore? ? Of course, in Espruino context we do not have a user...).

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Handling exceptions in setWatch/setInterval

Posted by Avatar for Gordon @Gordon