Google Apps Script V8 assignment to null cancels debugging
Asked Answered
E

1

6

A variable assignment to null causes debugging to cancel execution at that line. Here is a test script that reproduces the problem:

function myFunction() {
  var a = "Hallo";
  Logger.log("a=" + a);
  var b = null;
  Logger.log("b=" + b);
}

When debugging this script execution is cancelled on line "var b = null;". Log output is:

Mar 11, 2020, 8:52:49 PM    Info    a=Hallo
Mar 11, 2020, 8:52:54 PM    Info    Execution cancelled.

The result is the same when stepping over the line and running past the line in debug mode. However, in the latter case a red error message flashes for a moment at the top of the screen that says: "We're sorry, a server error occurred. Please wait a bit and try again."... waiting and retrying makes no difference. [Tried it again today after Jeff's comment below and was only able to recreate it by stepping over the assignment line in debug mode]

When running the script normally (not in debug) it completes successfully.

Equilibrist answered 11/3, 2020 at 19:12 Comment(8)
There is another V8 issue related to debug on the Issue Tracker: https://issuetracker.google.com/issues/149636786Vengeance
I couldn't reproduce your error, what steps are you following here? I do Run > Debug function > myFunctionMadaih
Thank you for the replies. Alan, I had a look at that issue and it might be related but I'm not sure to what extent. Jeff, yes that is how I did it and by stepping from a break point. However, I tried it now again and I couldn't recreate it by just doing Run > Debug function > myFunction. I could only recreate it by setting a break point and stepping over the line doing the null assignment.Equilibrist
@Equilibrist You could create a new issue in the issuetrackerSchoolgirl
Related: https://mcmap.net/q/1916187/-if-string-match-doesn-39-t-match-why-is-execution-of-google-apps-script-cancelledSchoolgirl
Thank you @TheMaster. The related issue you sent is explaining the same issue since there is also a null assignment with step-debugging. I'm considering creating an issue on issuetracker, but you mentioned that a new vscode based IDE is replacing the current one for Apps Script. Do you know when more-or-less?Equilibrist
Issuetracker issue is already logged: issue 150669095Equilibrist
Yes. IDE is in development. Not sure when they'll release. support.google.com/a/table/7539891Schoolgirl
R
2

I found temporary workaround:

Temporally (just for debugging) remove var for variable that takes null value.

Be careful: variable without var becomes global - so you can accidentally change value of the global variable with the same name.

But without the var you will not be able to see your variable in the debugger. So another workaround is to test your variable using if statement to see the value in the debugger:

change:

  var b = null;

temporally (just for debugging) to:

  b = null;
  if (b==null){
    var b0='null';
  } else {
    var b0=b;
  }

and observe b0 variable in the debugger

Ridley answered 30/5, 2020 at 11:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.