question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hi,

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:

https://github.com/jakesgordon/javascript-state-machine/blob/fcdd0fa17b734039dc641a033763e862de467749/state-machine.js#L95

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:closed
  • Created 9 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jakesgordoncommented, Jan 10, 2017

The try/catch error swallowing behavior has been removed in v3

0reactions
Pothercacommented, Aug 5, 2015

I am aware of this. I was also “bumping”. The question-mark was directed more towards @jakesgordon than the previous “bump” 😸

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is Error Handling? - Definition from Techopedia
Error handling refers to the response and recovery procedures from error conditions present in a software application. In other words, it is the...
Read more >
What is Exception Handling? - SearchSoftwareQuality
Exception handling is the process of responding to unwanted or unexpected events when a computer program runs. Exception handling deals with these events...
Read more >
Exception handling - Wikipedia
In computing and computer programming, exception handling is the process of responding to the occurrence of exceptions – anomalous or exceptional conditions ...
Read more >
Error handling - Express.js
Error Handling refers to how Express catches and processes errors that occur both synchronously and asynchronously. Express comes with a default error ...
Read more >
Control flow and error handling - JavaScript - MDN Web Docs
Exception handling statements. You can throw exceptions using the throw statement and handle them using the try...catch statements.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found