看见
try/catch block not catching async/await error
有关其他上下文,请回答您关于如何在
-在promisified版本中,当抛出错误时,您必须了解调用堆栈。
你有
ks3.download.start(param, (err, result) => {
//But how do I catch the exception start throw asynchronously ?
if (err) {
// error handling
} else {
log(`finished download ${file}`)
}
done()
})
您应该将其视为:
var cb = (err, result) => {
//But how do I catch the exception start throw asynchronously ?
if (err) {
// error handling
} else {
log(`finished download ${file}`)
}
done()
});
ks3.download.start(param, cb);
而且是
start
它本身抛出异常(在它开始调用或安排回调之前),所以您需要包装它
那个
调用一个try-catch:
var cb = (err, result) => {
//But how do I catch the exception start throw asynchronously ?
if (err) {
// error handling
} else {
log(`finished download ${file}`)
}
done()
});
try {
ks3.download.start(param, cb);
} catch (ex) {
// here.
}
我有点怀疑你
async.auto
callback
永远发挥作用
扔
(见
https://github.com/caolan/async/blob/master/lib/auto.js
),但是
https://github.com/ks3sdk/ks3-nodejs-sdk/blob/master/lib/api/download.js
如果
fs
因此,除了修复之外,你什么也做不了
ks3
或b)
找到一种方法来修补版本的
财政司司长
ks3
async.auto({
// ...
},
function(err, results) {
if (cb) {
if (err) {
cb(err);
return;
}
try {
fs.unlinkSync(configFile);
fs.renameSync(downFileName, filePath);
} catch (ex) {
cb(ex);
return;
}
cb(err, {msg:'success', path:filePath}, null);
} else {
// really, i wouldn't even bother fix this case and just make cb required.
}
})
最重要的是,我假设
ks3
如果出现错误,代码不会删除配置文件
有人回电话了。