首先,我必须为我糟糕的英语水平道歉我正在使用Google Apps Script
我有一个谷歌表,其中列a有50个链接Url(50行)我下面的脚本在运行demo时工作得非常好。
然而,问题是我的循环停止了,但没有错误消息当我设置触发器时,每次运行5分钟,并检查历史执行次数。
循环不完成全部50次,有时一次,有时49次。
无论结果如何,我希望它运行到最后一行(50)。你能帮忙吗?
我脚本
async function getJSON() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
const data = sheet.getRange("A1:A50").getValues()
for (var i = 1; i <=data.length; i++) {
try {
console.log(i)
const url = sheet.getRange(i, 1).getValue()
const content = await UrlFetchApp.fetch(url).getContentText("UTF-8");
const obj = JSON.parse(content);
....
...
} catch (e)
{ continue;
}
}
}
我想说的是,如果你在catch块中不包含console.log()或Logger.log(),你就不知道是否或发生了什么错误。
不带console.log()的脚本
function test() {
let a = 1;
for( let i=0; i<5; i++ ) {
try {
console.log(a/(b-i));
}
catch(err) {
continue;
}
}
}
执行日志
7:43:21 AM Notice Execution started
7:43:22 AM Notice Execution completed
使用console.log()的脚本
function test() {
let a = 1;
for( let i=0; i<5; i++ ) {
try {
console.log(a/(b-i));
}
catch(err) {
console.log(err)
continue;
}
}
}
执行日志
7:45:17 AM Notice Execution started
7:45:18 AM Info [ReferenceError: b is not defined]
7:45:18 AM Info [ReferenceError: b is not defined]
7:45:18 AM Info [ReferenceError: b is not defined]
7:45:18 AM Info [ReferenceError: b is not defined]
7:45:18 AM Info [ReferenceError: b is not defined]
7:45:17 AM Notice Execution completed