progress on error handling

This commit is contained in:
Jacob Nguyen
2023-10-02 22:01:15 -05:00
parent e954e2a399
commit f2218d02d4
4 changed files with 19 additions and 17 deletions

View File

@@ -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, ErrorResponse, Module, OnError, Processed } from '../types/core-modules';
import type { AnyModule, CommandModule, Module, OnError, Processed } from '../types/core-modules';
import type { ImportPayload } from '../types/core';
function createGenericHandler<Source, Narrowed extends Source, Output>(
@@ -149,6 +149,7 @@ interface ExecutePayload {
*/
export function executeModule(
emitter: Emitter,
logger: Logging|undefined,
errHandler: ErrorHandling,
{
module,
@@ -164,17 +165,22 @@ export function executeModule(
if (result.isOk()) {
emitter.emit('module.activate', SernEmitter.success(module));
return EMPTY;
} else {
if(onError) {
const err = onError() as CommandError.Response
if(!err) {
return throwError(() =>
SernEmitter.failure(module, "Failed to handle onError: returned nothing"));
}
return EMPTY
}
if(onError) {
const err = onError() as CommandError.Response
if(!err) {
return throwError(() =>
SernEmitter.failure(module, "Failed to handle onError: returned nothing"));
}
return throwError(() => SernEmitter.failure(module, result.error));
if(err.log) {
const { type, message } = err.log;
logger?.[type]({ message });
};
return EMPTY
}
return throwError(() => SernEmitter.failure(module, result.error));
}),
);
}

View File

@@ -13,7 +13,7 @@ import {
import { createInteractionHandler, executeModule, makeModuleExecutor } from './_internal';
import type { DependencyList } from '../types/ioc';
export function interactionHandler([emitter, err , , modules, client]: DependencyList) {
export function interactionHandler([emitter, err, log, modules, client]: DependencyList) {
const interactionStream$ = sharedEventStream<Interaction>(client, 'interactionCreate');
const handle = createInteractionHandler(interactionStream$, modules);
@@ -28,6 +28,6 @@ export function interactionHandler([emitter, err , , modules, client]: Dependenc
filterTap(e => emitter.emit('warning', SernEmitter.warning(e))),
makeModuleExecutor(module =>
emitter.emit('module.activate', SernEmitter.failure(module, SernError.PluginFailure))),
concatMap(payload => executeModule(emitter, err, payload)),
concatMap(payload => executeModule(emitter, log, err, payload)),
);
}

View File

@@ -42,6 +42,6 @@ export function messageHandler(
makeModuleExecutor(module => {
emitter.emit('module.activate', SernEmitter.failure(module, SernError.PluginFailure));
}),
concatMap(payload => executeModule(emitter, err, payload)),
concatMap(payload => executeModule(emitter, log, err, payload)),
);
}

View File

@@ -21,10 +21,6 @@ import { Awaitable, Args, SlashOptions, SernEventsMapping, AnyFunction } from '.
export type OnError = Record<string, AnyFunction>|undefined
export interface ErrorResponse<T> {
status: 'throw' | 'handle'
body: T
}
export interface CommandMeta {
fullPath: string;