From 78eb1f1c48ea2369b81e576b96ab8cfa4b3825e1 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Wed, 13 Nov 2024 15:33:12 +0800 Subject: [PATCH] Fix: track exception/rejection within single task --- Build/trace/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Build/trace/index.ts b/Build/trace/index.ts index c0736138..0116930a 100644 --- a/Build/trace/index.ts +++ b/Build/trace/index.ts @@ -1,4 +1,5 @@ import { basename, extname } from 'node:path'; +import process from 'node:process'; import picocolors from 'picocolors'; const SPAN_STATUS_START = 0; @@ -102,6 +103,15 @@ export function task(importMetaMain: boolean, importMetaPath: string) { const dummySpan = createSpan(taskName); if (importMetaMain) { + process.on('uncaughtException', (error) => { + console.error('Uncaught exception:', error); + process.exit(1); + }); + process.on('unhandledRejection', (reason) => { + console.error('Unhandled rejection:', reason); + process.exit(1); + }); + dummySpan.traceChildAsync('dummy', fn).finally(() => { dummySpan.stop(); printTraceResult(dummySpan.traceResult);