exception - 在 Google Cloud Function 中写入控制台时,不会写入任何内容
问题描述
我在 Google Cloud Function 中有一系列工作要做。如果我在本地运行脚本,它会在云函数中生成输出console
但不在云函数中。
// this is logged
console.error('An error');
for (var i=0; i<chunks.length; i++) {
const work = chunks[i].map(c => createOrUpdateTable(c, timestamp));
await Promise.all(work)
// this is not logged
.catch(e => console.error(e.message));
}
我试图把catch
函数和很多其他的东西放在里面,但行为相同。如何让错误出现在日志中?
解决方案
根据官方文档,您可以从 Cloud Function 向 Stackdriver Error Reporting 发出错误:
// These WILL be reported to Stackdriver Error Reporting
console.error(new Error('I failed you'));
console.error('I failed you', new Error('I failed you too'));
throw new Error('I failed you'); // Will cause a cold start if not caught
// These will NOT be reported to Stackdriver Error Reporting
console.info(new Error('I failed you')); // Logging an Error object at the info level
console.error('I failed you'); // Logging something other than an Error object
throw 1; // Throwing something other than an Error object
callback('I failed you');
res.status(500).send('I failed you');
推荐阅读
- c# - 从 CollectionView 绑定 SelectedItem
- c# - 为什么 ClaimTypes.NameIdentifier 没有映射到“sub”?
- c - flatcc union 作为顶部元素
- javascript - 管理在 JavaScript 中的动态元素中制作的计时器
- asp.net-mvc - reCAPTCHA v3 中的低分怎么办?
- angular - 使用 ng2-completer 时如何使用 json 对象中的特定字段作为数据源?
- julia - 在 Julia 中调用外部命令
- angular7 - 如何使 Angular 7 应用程序与 Microsoft Edge 浏览器兼容?
- python - 如何正确导入单元测试的相对路径
- r - 尝试在 Mac 上安装 devtools 时出错