From 9e08afbccd0ce59dc97a82c7b2448ecf6e7ed4c9 Mon Sep 17 00:00:00 2001 From: undefined Date: Sun, 30 Aug 2026 15:40:49 +0000 Subject: [PATCH] core: fix aggregate error handle --- framework/framework/server.ts | 13 +++++++++---- packages/hydrooj/package.json | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/framework/framework/server.ts b/framework/framework/server.ts index 2a15146e4..05d8d448e 100644 --- a/framework/framework/server.ts +++ b/framework/framework/server.ts @@ -56,6 +56,10 @@ async function forkContextWithScope(ctx: CordisContext) { }; } +function unwrapAggregateError(error: any) { + return error instanceof AggregateError ? error.errors[0] : error; +} + export interface HydroRequest { method: string; host: string; @@ -601,11 +605,12 @@ ${c.response.status} ${endTime - startTime}ms ${c.response.length}`); } else current++; } } catch (e) { + const error = unwrapAggregateError(e); try { // FIXME: should pass type check - await (this.ctx.serial as any)(`handler/error/${name}`, h, e); - await (this.ctx.serial as any)('handler/error', h, e); - await h.onerror(e); + await (this.ctx.serial as any)(`handler/error/${name}`, h, error); + await (this.ctx.serial as any)('handler/error', h, error); + await h.onerror(error); } catch (err) { logger.error(err); h.response.status = 500; @@ -726,7 +731,7 @@ ${c.response.status} ${endTime - startTime}ms ${c.response.length}`); } } catch (e) { // error during initialization (prepare, hooks) - await clean(e); + await clean(unwrapAggregateError(e)); } } diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index e178db97c..12630c36f 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "5.0.5", + "version": "5.0.6", "bin": "bin/hydrooj.js", "main": "src/plugin-api", "module": "src/plugin-api",