From e954e2a3997ec09a90fa398ed05f0c6cdba15d60 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Mon, 2 Oct 2023 11:07:13 -0500 Subject: [PATCH] fix merge --- src/core/contracts/error-handling.ts | 2 +- src/handlers/event-utils.ts | 9 ++++++--- src/types/core-modules.ts | 5 +++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/core/contracts/error-handling.ts b/src/core/contracts/error-handling.ts index ebeb7d4..7d17a56 100644 --- a/src/core/contracts/error-handling.ts +++ b/src/core/contracts/error-handling.ts @@ -10,7 +10,7 @@ export interface ErrorHandling { */ crash(err: Error): never; /** - * A function that is called on every crash. + * A function that is called on every throw. * @param error */ updateAlive(error: Error): void; diff --git a/src/handlers/event-utils.ts b/src/handlers/event-utils.ts index aace6f4..9e82b06 100644 --- a/src/handlers/event-utils.ts +++ b/src/handlers/event-utils.ts @@ -30,7 +30,7 @@ import { SernEmitter } from '../core'; import { Err, Ok, Result } from 'ts-results-es'; import type { AnyFunction, Awaitable } from '../types/utility'; import type { ControlPlugin } from '../types/core-plugin'; -import type { AnyModule, CommandModule, Module, OnError, Processed } from '../types/core-modules'; +import type { AnyModule, CommandModule, ErrorResponse, Module, OnError, Processed } from '../types/core-modules'; import type { ImportPayload } from '../types/core'; function createGenericHandler( @@ -166,8 +166,11 @@ export function executeModule( return EMPTY; } else { if(onError) { - const payload = onError() as CommandError.Response - + const err = onError() as CommandError.Response + if(!err) { + return throwError(() => + SernEmitter.failure(module, "Failed to handle onError: returned nothing")); + } return EMPTY } return throwError(() => SernEmitter.failure(module, result.error)); diff --git a/src/types/core-modules.ts b/src/types/core-modules.ts index f098eca..9db81a3 100644 --- a/src/types/core-modules.ts +++ b/src/types/core-modules.ts @@ -21,6 +21,11 @@ import { Awaitable, Args, SlashOptions, SernEventsMapping, AnyFunction } from '. export type OnError = Record|undefined +export interface ErrorResponse { + status: 'throw' | 'handle' + body: T +} + export interface CommandMeta { fullPath: string; id: string;