From 10bde9f1e81e9876ca34853da6c3ae61fe9e503f Mon Sep 17 00:00:00 2001 From: SukkaW Date: Thu, 2 May 2024 07:33:29 +0800 Subject: [PATCH] Fix/CI: float promise error handling / log wrap --- Build/lib/memo-promise.ts | 16 +++++++++++++++- Build/trace/index.ts | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Build/lib/memo-promise.ts b/Build/lib/memo-promise.ts index 5e26332a..f76d05bc 100644 --- a/Build/lib/memo-promise.ts +++ b/Build/lib/memo-promise.ts @@ -1,7 +1,21 @@ +const notError = Symbol('notError'); + export const createMemoizedPromise = (fn: () => Promise, preload = true): () => Promise => { - let promise: Promise | null = preload ? fn() : null; + let error: Error | typeof notError = notError; + + let promise: Promise | null = preload + ? fn().catch(e => { + // Here we record the error so that we can throw it later when the function is called + error = e; + // Here we make sure the Promise still returns the never type + throw e; + }) + : null; return () => { + if (error !== notError) { + return Promise.reject(error); + } promise ??= fn(); return promise; }; diff --git a/Build/trace/index.ts b/Build/trace/index.ts index ae82da27..4f986d18 100644 --- a/Build/trace/index.ts +++ b/Build/trace/index.ts @@ -181,7 +181,7 @@ function printStats(stats: TraceResult[]): void { const realStart = Math.min(...stats.map(i => i.start)); const realEnd = Math.max(...stats.map(i => i.end)); - const statsStep = ((realEnd - realStart) / 160) | 0; + const statsStep = ((realEnd - realStart) / 120) | 0; stats.forEach(stat => { console.log(