From 8bbf9c46a32ca6d37678e4ed4c420a4845ec1830 Mon Sep 17 00:00:00 2001 From: Anton Nikolaev Date: Tue, 18 May 2021 08:06:07 -0700 Subject: [PATCH] Keep promise rejections unhandled after catching them for logging Summary: Tracked component catches rejected promises under it to log them. After catching promises become "handled". This might hide potential promise error handling mistakes, so it's better to ensure we keep promises unhandled after catching them for tracking, so they are properly catched by the unhandled promise handler after that. The easiest solution seems to just make new rejected promise and return it instead of the catched one. Reviewed By: passy Differential Revision: D28466570 fbshipit-source-id: 26c1e7af3d6e4f7067b95f20e646462d808bb497 --- desktop/app/src/init.tsx | 2 +- desktop/flipper-plugin/src/ui/Tracked.tsx | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/desktop/app/src/init.tsx b/desktop/app/src/init.tsx index 028a36a0e..291cbe638 100644 --- a/desktop/app/src/init.tsx +++ b/desktop/app/src/init.tsx @@ -187,7 +187,7 @@ function init() { if (!isProduction()) { const msg = `[interaction] ${r.scope}:${r.action} in ${r.duration}ms`; if (r.success) console.log(msg); - else console.error(msg, r.error); + else console.warn(msg, r.error); } }); ReactDOM.render( diff --git a/desktop/flipper-plugin/src/ui/Tracked.tsx b/desktop/flipper-plugin/src/ui/Tracked.tsx index 88274b181..2dcf76e35 100644 --- a/desktop/flipper-plugin/src/ui/Tracked.tsx +++ b/desktop/flipper-plugin/src/ui/Tracked.tsx @@ -161,12 +161,16 @@ export function wrapInteractionHandler( throw e; } const initialEnd = Date.now(); - if (typeof res?.then === 'function') { + if (typeof res?.then === 'function' && typeof res?.catch === 'function') { // async / promise res.then( () => r(initialEnd), (error: any) => r(initialEnd, error), ); + res = res.catch((error: any) => { + // we need to create another rejected promise so error is again marked as "unhandled" + return Promise.reject(error); + }); } else { // not a Promise r(initialEnd);