You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am getting an error that shows little to no information.
[object Object] thrown
After a few days of testing and trying to figure out the issue I decided to modify ExceptionFormatter.message(). Which produced the output needed to figure out what was wrong.
Could we maybe JSON.stringify() the error (maybe with a better approach than below).
You didn't describe how to reproduce the problem but I'm guessing that you have code that throws something that's not an Error instance. Although JavaScript allows pretty much any value to be thrown, it's a lot harder for tools like Jasmine to provide you with useful information when it's not an Error. For instance, Jasmine can only display stack traces for Error instances because nothing else has them. My guess is that a stack trace would've saved you a lot of debugging time.
The problem with JSON.stringify is that not all objects are JSON serializable, and not all of the ones that are produce a serialization that's as useful in a context like this as the result of toString. I'm open to other suggestions but I think most possible changes would be lateral moves at best, making the output better in some cases and worse in others.
I recommend always using Error instances when throwing or rejecting promises. If you have to use something else, it's a good idea to override toString to return whatever description of the object you'd want to see.
Also, most JS debuggers have the ability to break when an exception is thrown. You might find that useful the next time you run into this kind of problem, whether it's in Jasmine or elsewhere.
I am getting an error that shows little to no information.
After a few days of testing and trying to figure out the issue I decided to modify
ExceptionFormatter.message()
. Which produced the output needed to figure out what was wrong.Could we maybe
JSON.stringify()
the error (maybe with a better approach than below).The text was updated successfully, but these errors were encountered: