This issue has been reported to Google: https://issuetracker.google.com/issues/152948662
A short description of the issue
In the Rhino runtime, the script debugger (script.google.com) would break on any line containing an error (handled or not) if the uses pressed the "debug" button on the toolbar. (It won't break if the user presses the "run" button). The watch windows would be activated and the user can inspect the variables in force at the time of the error.
In the V8 runtime, the script debugger will not break on any error under any circumstances. This is very unhandy for debugging.
A small code sample that reliably reproduces the issue
The sample should run as-is or with minimal setup, without external dependencies
function testError() {
var a = {
title: function() { console.log('hello world') }
}
a.titel(); // rhino would break here because of this (unintentional) typo; V8 will not.
}
What steps will reproduce the problem?
Create a new project
Insert the code into Code.gs
Debug the code
What is the expected output? What do you see instead? If you see error messages, please provide them.
Expected: debugger breaks on line with asdfgh()
Actual: debugger exits debugging
Messages: the debugger (very) briefly shows the error as a toast and logs the unhandled error under logs and executions.
Please provide any additional information below:
Side note: not important for this bug. Just extra info FYI. Don't let this distract you or trip you up
If this bug can be fixed, I can use my homegrown function that effectively allows me to have "breakpoints" anywhere in the code, thus getting around another bug GAS debugger has (breakpoints only hit on current file):
Break(condition, watch) {
try {
if(!App.Objects.isUndefined(condition) && !condition)
return false;
// you have to step over until you leave Break(). Run doesn't work from here.
thisFuncDoesntExist();
} catch (e) {
return true;
}
}
Under Rhino, I could put a call to this anywhere and the debugger would stop for me there. But this is just a side note.
You should use the JS statement debugger
. It's the standard way to insert breakpoints for debugging in Javascript. In GAS use the debug button to run your function and the execution will stop at every debugger;
statement.
For example you will be able to update your testError
function like this:
function testError() {
var a = 'hello world';
debugger;
}
V8 GAS Runtime debugger won't pause on exceptions. You will have to explicitly insert breakpoints in order to pause the running process.
You could wrap your function in a try-catch
in order to trigger the debugger on unhandled exceptions.
function myFunction() {
try {
// myFunction body...
} catch(e) {
debugger;
}
}
However, if you really need this feature you can switch back to the old runtime.
In the manifest file change this parameter:
"runtimeVersion": "DEPRECATED_ES5"
This comes at a price though: you won't be able to use modern JavaScript syntax.