Can I make Chrome more descriptive of errors? - javascript

I'm new to BDD with Jasmine. In fact, I've just downloaded Jasmine, written my first spec, and launched the SpecRunner.html file. I have yet to write a particular init method, and in Firefox/Safari I see a nice description of this error:
(Firefox) TypeError: Object.create(...).init is not a function in file...
(Safari) TypeError: undefined is not a function (evaluating 'Object.create(Seminar).init(seminarName)') in file...
However, in Chrome I see a technically correct, but disappointingly obtuse error:
TypeError: undefined is not a function
at Object.Seminar.create (file...Seminar.js:7:39)
Is there a way to make Chrome tell me the actual name of the missing method, as opposed to just the line number and column name of where the error occurred?

Is there a way to make Chrome tell me the actual name of the missing method, as opposed to just the line number and column name of where the error occurred?
No, but looking at the line and column should tell you what it is. You can also use Chrome's Dev Tools to make it stop execution on an exception that isn't handled, which will take you right to the place where the exception occurs, when it occurs, so you can inspect things. To do that:
Open Dev Tools
Go to the Sources pane
Click this icon on the right-hand side to turn it blue:
When that icon is blue, it will make Chrome stop when an exception occurs that isn't caught (there's also a checkbox that will appear if you want to stop on exceptions that are caught).

Related

onmozfullscreenchange warning in Firefox (not using react)

I keep getting this error in Firefox console.
onmozfullscreenchange is deprecated. editresume.js:411:4
onmozfullscreenerror is deprecated. editresume.js:411:4
Ignoring get or set of property that has [LenientThis] because the “this” object is incorrect.
If I go to my code file, for that line number, this is what I have
tempbutton.setAttributeNode(attid);
and, I am not using onmozfullscreenchange or onmozfullscreenerror anywhere.
Why am I getting this? It is also triggers a debugger exception for some reason, at that line number.
Note : I dont get a similar error/warning/breakpoint trigger on Chrome. So, its Firefox only.
Firefox version - 70.0
Chrome version - 77.0.X
This message may appear when logging the window or document objects and extending the resulting message in the Console.
It's because these getters are configured to warn about this deprecation so that developers can update their code accordingly.
However, this deprecation notice doesn't look at what tried to get it, so when the Console itself tries to get the value of these properties, it will also trigger the warning notification.
But your debugger exception certainly comes from somewhere else.

JavaScript errors does not show in the console

I'm developing a js game and I debug it using Chrome DevTools.
Recently I noticed that some errors are not reported to the console even though they freeze the code execution.
The only way I can debug those errors is running row by row until I see the error while hovering over the problematic variable. (for ex. trying to read a property of an 'undefined' variable (TypeError))
If it matters I use 'use strict' as well.
Update: I noticed that if I check 'Pause on caught exceptions' the code will stop on the error. What can cause such error to be caught without using a trycatch around it?
Thank you

How to get Chrome debugger to break or error when working on undefined variables

My Javascript code (hundreds of lines) hangs Chrome and when I debug the issue I find out that a variable was undefined. I don't get errors in the console. So this is making my debugging more time consuming because there are no errors or exceptions or anything that tells me where the issue is.
I don't want to add debugging code. Is there a way to make the debugger put out an error, break in the debugger or give an exception or show anything useful for the developer when hitting an undefined variable during runtime? It doesn't have to be for Chrome only.
You can break into the DevTools debugger when a JavaScript error occurs using the Pause on JavaScript Exceptions feature. It has two active modes; pause on all exceptions, and pause on uncaught exceptions.
Based on the description of your experience, the application you are working on may have errors that are caught but not re-thrown or logged. Using the "Pause on All Exceptions" (blue colored pause icon), will help in this scenario.
Note: some libraries, like jQuery, catch exceptions and do not re-throw them. If you have this experience, you may need to advance past these exceptions or set the "Pause on All Exceptions" feature after all dependencies have loaded.
window.onerror = function() { debugger; }

Showing JavaScript exception message in Chrome dev tools

I'm using Chrome development tools to debug my JavaScript. When I tell Chrome "Not to pause on exceptions" and load my script, I get an intelligible description of what went wrong with the correct line highlighted:
var back_buffer = goog.dom.getElement('back_buffer').getContext('2d');
--> "Uncaught TypeError: Cannot call method 'getContext' of null"
OK, it makes sense: there's a typo in the name of my canvas element so 'getElement' returns null.
Now on to my question: when I tell Chrome to 'pause on uncaught exceptions', it still correctly highlights the offending line in my script, but now the nice, intelligible error descriptions is gone! How come? Even in debug mode I'd like to see the error message because it's very helpful. I poked around but couldn't find it anywhere.
Anybody could help here?
There does not appear to be good way to do this currently. This is the closest you can get:
The error is not showing because the execution of that script is paused just before it goes into the exception.
It's pausing right before the error so you can debug some things in the console.
What i tend to do in the situation you talk about, and the scope variables are not giving any more info, is add some watch expressions or execute some commands in the console.
In your back_buffer case you could for instance add a watch expression like this goog.dom.getElement('back_buffer') so you could see what it resolves to. If that expression causes an error you will see the error message there like you would after the script error occurred.
It might not be completely obvious to some people that when script execution is halted the execution context is the same as the execution context of the script at the time it paused, so all local variables are accessible in the console to console.log() or console.dir() or anything.
When you have pretty print set to on there will be not that much going on on that one line it paused at so mostly you shouldn't have to search for long to get an idea of what's causing the error and why.
Hope it helps,
PM5544.
You should be able see the same text in a red bubble message just under the offending source line once it executes.
Just do one more 'Step' and the red bubble will appear. This is logical as it pauses before the error/bubble behavior happens.
What if you catch the exception and send it to the log:
try
{
var back_buffer = goog.dom.getElement('back_buffer').getContext('2d');
}
catch(err)
{
console.log(err);
}
Once in the console you can examine the object in more detail.

Javascript: object expected on line 1 char 2

http://pastie.org/856698
Anyone have any idea why the script is causing this error?
Check your jQuery file to see if you don't have extra characters in there. That is the first referenced script and your error doesn't give a file.
UPDATE:
I'm not getting any errors on your site in IE8 until I press submit. Then it tells me regSubmit() is not an object, and indeed it isn't, your function is called submitReg(). Perhaps the reason you are getting errors "in IE" is simply because without a debugger loaded, non-IE browsers tend to just skip errors, whereas IE stops processing and puts up a notification.
Try installing Firebug or using Chrome, CTRL+SHIFT+J and watch and see if you get errors there now (you will if you watch the console, but processing will continue anyway).

Categories