Error handling
See original GitHub issueHi,
I’ve got a problem with the way the state machine is handling the errors happening in “caller-provided”.
I spent an hour finding out a bug as the error displayed was: “an exception occurred in a caller-provided callback function”, displayed from a try-catch that is part of the library:
I understand the attempt in trying to give more information about the states when something wrong is happening but the problem is that it is really masking completely the real error.
I tried to log the error from the try catch in the state machine but all I got was a useless: TypeError {}
with no information at all. Not sure why I couldn’t propagate the real error on my side. I don’t have a try-catch at that level in my code but we are using a large tv application framework that might have some. Anyway, that’s out of my reach.
I found the issue in my code by removing the try-catch from the state-machine and calling the callback directly, all finally got the error description, in which javascript file, at what line.
Conceptually, I do not think that the state machine should have a try-catch there for several reasons:
- it is not the matter of the library to care about what is happening outside of its scope
- it is masking the real problem really well
- solving bugs inside those callback is REALLY HARD, I can’t remember the last time I had a problem like this
- providing state information when an error occurs is of little interest compared to get information about the real problem
- the user can still add a try-catch on a higher level, which is better
The only things the state machine should do is have a a condition that checks that the function is actually a function, and that’s it:
if (typeof func === 'function') {
return func.apply(fsm, [name, from, to].concat(args));
}
Would you consider a pull request to remove the try-catch? We are re-building a large TV application and I need it rock solid. I’d prefer to contribute to the original library rather than using my own fork.
Cheers.
Romu
Issue Analytics
- State:
- Created 9 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
The try/catch error swallowing behavior has been removed in v3
I am aware of this. I was also “bumping”. The question-mark was directed more towards @jakesgordon than the previous “bump” 😸