Javascript ES6 async/await在出现故障时如何处理可观察对象和流?

Javascript ES6 async/await在出现故障时如何处理可观察对象和流?,javascript,node.js,rxjs,es6-promise,Javascript,Node.js,Rxjs,Es6 Promise,所以,我一直在尝试复制这段代码: 它是有效的。但是,如果承诺失败,我会收到“未处理的承诺”警告。如果有的话,像这样的东西的catch语句属于哪里?有没有更好的方法来获取这样的信息 (node:48454) UnhandledPromiseRejectionWarning: Error: Command failed: np patch --no-cleanup at makeError (/Users/daghassi/git/build/node_modules/execa/in

所以,我一直在尝试复制这段代码:

它是有效的。但是,如果承诺失败,我会收到“未处理的承诺”警告。如果有的话,像这样的东西的catch语句属于哪里?有没有更好的方法来获取这样的信息

(node:48454) UnhandledPromiseRejectionWarning: Error: Command failed: np patch --no-cleanup


    at makeError (/Users/daghassi/git/build/node_modules/execa/index.js:172:9)
    at Promise.all.then.arr (/Users/daghassi/git/build/node_modules/execa/index.js:277:16)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:160:7)
(node:48454) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 5)
(node:48454) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:48454) UnhandledPromiseRejectionWarning: Error: Command failed: np patch --no-cleanup


    at makeError (/Users/daghassi/git/build/node_modules/execa/index.js:172:9)
    at Promise.all.then.arr (/Users/daghassi/git/build/node_modules/execa/index.js:277:16)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:160:7)
(node:48454) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 6)
(node:48454) UnhandledPromiseRejectionWarning: Error: Command failed: np patch --no-cleanup
(节点:48454)未处理的PromisejectionWarning:错误:命令失败:np修补程序--无清理
在makeError(/Users/daghassi/git/build/node_modules/execa/index.js:172:9)
在Promise.all.then.arr(/Users/daghassi/git/build/node_modules/execa/index.js:277:16)
在
在进程中。_tick回调(内部/process/next_tick.js:160:7)
(节点:48454)未处理的PromisejectionWarning:未处理的承诺拒绝。此错误源于在没有catch块的异步函数中抛出,或者拒绝未使用.catch()处理的承诺。(拒绝id:5)
(节点:48454)[DEP0018]弃用警告:未处理的承诺拒绝已弃用。将来,未处理的承诺拒绝将使用非零退出代码终止Node.js进程。
(节点:48454)未处理的PromisejectionWarning:错误:命令失败:np修补程序--无清理
在makeError(/Users/daghassi/git/build/node_modules/execa/index.js:172:9)
在Promise.all.then.arr(/Users/daghassi/git/build/node_modules/execa/index.js:277:16)
在
在进程中。_tick回调(内部/process/next_tick.js:160:7)
(节点:48454)未处理的PromisejectionWarning:未处理的承诺拒绝。此错误源于在没有catch块的异步函数中抛出,或者拒绝未使用.catch()处理的承诺。(拒绝id:6)
(节点:48454)未处理的PromisejectionWarning:错误:命令失败:np修补程序--无清理

只需在等待呼叫周围放置一个try/catch块即可。这应该与调用Promise并提供catch函数相同

因此,如果您有一个返回承诺的函数
getPromise()
,您只需执行此操作

async function asyncFunction() {
    try {
        const result = await getPromise();
    } catch (error) {
        // Add your error handling code here
    }
}

可以添加堆栈跟踪吗please@NaorTedgi更新了original,其中包含通过此方法调用的命令在退出时抛出错误时看到的堆栈跟踪示例。将async关键字用于函数定义