javascript - @Google-cloud/storage 在工作了很长时间后突然抛出奇怪的异常
问题描述
语境:
我有一个 API 端点,它提供存储在公共 Google Cloud Storage 存储桶中的 .stl 文件。直到本周的某个时候,它工作正常。我可以使用调试器逐步完成我的代码。我的项目中甚至没有引用有问题的 NPM 模块。我尝试使用 Google 文档上的确切代码进行下载并得到相同的异常:https ://github.com/googleapis/nodejs-storage/blob/master/samples/downloadFile.js
我试过的
npm rebuild @google-cloud/storage
以及使用相同 Google npm 包的不同方式。
问题:
1.)不应该捕获,捕获异常以防止崩溃吗?
2.) 有人对解决方法有任何想法吗?
文件: https ://storage.cloud.google.com/fancy_induction_ui/1inX1in.stl
代码:
getFile: async (req, res) => {
try {
const fileName = req.param('file');
res.setHeader('Content-Type', 'application/octet-stream');
res.setHeader('Content-Disposition', 'attachment; filename=' + fileName + '');
const storage = new Storage();
let file = await storage.bucket('fancy_induction_ui').file(fileName).createReadStream();
file.pipe(res);
} catch (e) {
res.status(500).json({message: 'Something is wrong!', err: e.message});
}
}
堆栈跟踪:
path/to/code/node_modules/readable-stream/lib/_stream_writable.js:317
var isBuf = !state.objectMode && _isUint8Array(chunk);
^
TypeError: Cannot read property 'objectMode' of undefined
at DestroyableTransform.Writable.write (path/to/code/node_modules/readable-stream/lib/_stream_writable.js:317:22)
at PassThrough.ondata (_stream_readable.js:714:22)
at PassThrough.emit (events.js:321:20)
at PassThrough.EventEmitter.emit (domain.js:482:12)
at PassThrough.Readable.read (_stream_readable.js:512:10)
at flow (_stream_readable.js:989:34)
at resume_ (_stream_readable.js:970:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
解决方案
在我看来,深度依赖中不同版本的可读流中的错误。我已经添加了
readable-stream: "3.6.0"
到我的 package.lock ,这对我来说是固定的这个问题。
推荐阅读
- android - 如果 listA = List.from(listB) 在颤动中,如何防止元素不从 listB 编辑并从 listA 编辑?
- python - Scrapy登录到网站,登录数据显示在重定向的url中
- java - 那是什么建筑?这是什么意思?
- asp.net - 如何使用带有计数的 linq 组并将 ToListAsync 返回到前端
- python-3.x - 读取包含日期数据的csv文件,格式为:dd/mm/yyyy in python
- ios - 在不考虑状态栏高度的情况下将 UIPageViewController 添加到父 UIViewController 的好方法是什么?
- code-coverage - 机会发送电子邮件
- flutter - 动态选项卡数
- javascript - 使用 JavaScript 而不是 html 提交值
- sql - 使用 SQL 窗口函数填充 1 列值为 0 的行,可能使用行索引的下一个最大/上一个最小值