From 4b5b3e0dadb61b9ddd8ae7d1dc5fa22dddd4ef2e Mon Sep 17 00:00:00 2001 From: James Cleveland Date: Sun, 13 Jul 2025 00:09:54 +0100 Subject: [PATCH 1/3] implement prerender queue failOnError --- .../start-plugin-core/src/nitro-plugin/prerender.ts | 5 ++++- packages/start-plugin-core/src/nitro-plugin/queue.ts | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/start-plugin-core/src/nitro-plugin/prerender.ts b/packages/start-plugin-core/src/nitro-plugin/prerender.ts index 287516e173..51c04bde38 100644 --- a/packages/start-plugin-core/src/nitro-plugin/prerender.ts +++ b/packages/start-plugin-core/src/nitro-plugin/prerender.ts @@ -132,7 +132,10 @@ export async function prerender({ const retriesByPath = new Map() const concurrency = options.prerender?.concurrency ?? os.cpus().length logger.info(`Concurrency: ${concurrency}`) - const queue = new Queue({ concurrency }) + const queue = new Queue({ + concurrency, + failOnError: options.prerender?.failOnError, + }) options.pages.forEach((page) => addCrawlPageTask(page)) diff --git a/packages/start-plugin-core/src/nitro-plugin/queue.ts b/packages/start-plugin-core/src/nitro-plugin/queue.ts index 279146fdb2..215a43a52c 100644 --- a/packages/start-plugin-core/src/nitro-plugin/queue.ts +++ b/packages/start-plugin-core/src/nitro-plugin/queue.ts @@ -2,6 +2,7 @@ interface PoolConfig { concurrency?: number started?: boolean tasks?: Array<() => Promise> + failOnError?: boolean } const defaultConfig: PoolConfig = { @@ -19,15 +20,17 @@ export class Queue { private active: Array<() => Promise> = [] private pending: Array<() => Promise> private currentConcurrency: number + private failOnError: boolean constructor(config: PoolConfig = defaultConfig) { - const { concurrency, started, tasks } = { + const { concurrency, started, tasks, failOnError } = { ...defaultConfig, ...config, } this.running = started! this.pending = tasks as Array<() => Promise> this.currentConcurrency = concurrency! + this.failOnError = Boolean(failOnError) } private tick() { @@ -51,6 +54,11 @@ export class Queue { res = await nextFn() success = true } catch (e) { + if (this.failOnError) { + this.stop() + this.clear() + throw e + } error = e } this.active = this.active.filter((d) => d !== nextFn) From 63d65e24bb5008ac5353dcac4ade9bcd07ec02ba Mon Sep 17 00:00:00 2001 From: James Cleveland Date: Sun, 13 Jul 2025 09:30:49 +0100 Subject: [PATCH 2/3] hard exit on failure --- packages/start-plugin-core/src/nitro-plugin/queue.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/start-plugin-core/src/nitro-plugin/queue.ts b/packages/start-plugin-core/src/nitro-plugin/queue.ts index 215a43a52c..e3c674f4e8 100644 --- a/packages/start-plugin-core/src/nitro-plugin/queue.ts +++ b/packages/start-plugin-core/src/nitro-plugin/queue.ts @@ -1,3 +1,4 @@ + interface PoolConfig { concurrency?: number started?: boolean @@ -55,9 +56,8 @@ export class Queue { success = true } catch (e) { if (this.failOnError) { - this.stop() - this.clear() - throw e + console.error(e); + process.exit(1); } error = e } From ef5a702698e2a61efbd010c8279ac67ffdfcb4d3 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Sun, 13 Jul 2025 08:31:55 +0000 Subject: [PATCH 3/3] ci: apply automated fixes --- packages/start-plugin-core/src/nitro-plugin/queue.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/start-plugin-core/src/nitro-plugin/queue.ts b/packages/start-plugin-core/src/nitro-plugin/queue.ts index e3c674f4e8..4f589b8845 100644 --- a/packages/start-plugin-core/src/nitro-plugin/queue.ts +++ b/packages/start-plugin-core/src/nitro-plugin/queue.ts @@ -1,4 +1,3 @@ - interface PoolConfig { concurrency?: number started?: boolean @@ -56,8 +55,8 @@ export class Queue { success = true } catch (e) { if (this.failOnError) { - console.error(e); - process.exit(1); + console.error(e) + process.exit(1) } error = e }