将Google Apps Script V8分配为null会取消调试 [英] Google Apps Script V8 assignment to null cancels debugging

查看:65
本文介绍了将Google Apps Script V8分配为null会取消调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将变量赋值为null会导致调试取消该行的执行. 这是一个重现该问题的测试脚本:

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);
}

调试时,此脚本的执行在"var b = null;"行上被取消.日志输出为:

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.

在调试模式下越过该行并越过该行时,结果是相同的.但是,在后一种情况下,红色错误消息会在屏幕顶部闪烁一会儿,提示:很抱歉,发生服务器错误.请稍等片刻,然后重试." ...等待并重试没有不同. [今天在Jeff发表以下评论后再次尝试过,并且只能通过在调试模式下跳过分配行来重新创建它]

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.

推荐答案

我发现了临时解决方法:

I found temporary workaround:

暂时(仅用于调试)将var删除为具有null值的变量.

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

请注意:没有var的变量将变为全局变量-因此您可能会意外更改具有相同名称的全局变量的值.

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

但是如果没有var,您将无法在调试器中看到您的变量.因此,另一个解决方法是使用if语句测试变量,以查看调试器中的值:

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:

更改:

  var b = null;

暂时(仅用于调试):

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

并在调试器中观察b0变量

这篇关于将Google Apps Script V8分配为null会取消调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆