mirror of
https://github.com/sern-handler/handler
synced 2026-06-15 04:12:17 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a19edaf883 | ||
|
|
90e55dfa14 |
@@ -1,5 +1,12 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [3.3.4](https://github.com/sern-handler/handler/compare/v3.3.3...v3.3.4) (2024-03-18)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* sern emitter err ([#358](https://github.com/sern-handler/handler/issues/358)) ([90e55df](https://github.com/sern-handler/handler/commit/90e55dfa1466c91e5da48922251309331921b1ef))
|
||||||
|
|
||||||
## [3.3.3](https://github.com/sern-handler/handler/compare/v3.3.2...v3.3.3) (2024-02-25)
|
## [3.3.3](https://github.com/sern-handler/handler/compare/v3.3.2...v3.3.3) (2024-02-25)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@sern/handler",
|
"name": "@sern/handler",
|
||||||
"packageManager": "yarn@3.5.0",
|
"packageManager": "yarn@3.5.0",
|
||||||
"version": "3.3.3",
|
"version": "3.3.4",
|
||||||
"description": "A complete, customizable, typesafe, & reactive framework for discord bots.",
|
"description": "A complete, customizable, typesafe, & reactive framework for discord bots.",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"module": "./dist/index.mjs",
|
"module": "./dist/index.mjs",
|
||||||
|
|||||||
@@ -59,13 +59,14 @@ export const sharedEventStream = <T>(e: Emitter, eventName: string) => {
|
|||||||
return (fromEvent(e, eventName) as Observable<T>).pipe(share());
|
return (fromEvent(e, eventName) as Observable<T>).pipe(share());
|
||||||
};
|
};
|
||||||
|
|
||||||
export function handleError<C>(crashHandler: ErrorHandling, logging?: Logging) {
|
export function handleError<C>(crashHandler: ErrorHandling, emitter: Emitter, logging?: Logging) {
|
||||||
return (pload: unknown, caught: Observable<C>) => {
|
return (pload: unknown, caught: Observable<C>) => {
|
||||||
// This is done to fit the ErrorHandling contract
|
// This is done to fit the ErrorHandling contract
|
||||||
const err = pload instanceof Error ? pload : Error(util.inspect(pload, { colors: true }));
|
if(!emitter.emit('error', pload)) {
|
||||||
//formatted payload
|
const err = pload instanceof Error ? pload : Error(util.inspect(pload, { colors: true }));
|
||||||
logging?.error({ message: util.inspect(pload) });
|
logging?.error({ message: util.inspect(pload) });
|
||||||
crashHandler.updateAlive(err);
|
crashHandler.updateAlive(err);
|
||||||
|
}
|
||||||
return caught;
|
return caught;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export class DefaultErrorHandling implements ErrorHandling {
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
#keepAlive = 5;
|
#keepAlive = 1;
|
||||||
|
|
||||||
updateAlive(err: Error) {
|
updateAlive(err: Error) {
|
||||||
this.#keepAlive--;
|
this.#keepAlive--;
|
||||||
|
|||||||
@@ -246,9 +246,9 @@ export function makeModuleExecutor<
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const handleCrash = (err: ErrorHandling, log?: Logging) =>
|
export const handleCrash = (err: ErrorHandling,sernemitter: Emitter, log?: Logging) =>
|
||||||
pipe(
|
pipe(
|
||||||
catchError(handleError(err, log)),
|
catchError(handleError(err, sernemitter, log)),
|
||||||
finalize(() => {
|
finalize(() => {
|
||||||
log?.info({
|
log?.info({
|
||||||
message: 'A stream closed or reached end of lifetime',
|
message: 'A stream closed or reached end of lifetime',
|
||||||
|
|||||||
@@ -31,6 +31,6 @@ export function eventsHandler(
|
|||||||
* Where all events are turned on
|
* Where all events are turned on
|
||||||
*/
|
*/
|
||||||
mergeAll(),
|
mergeAll(),
|
||||||
handleCrash(err, log))
|
handleCrash(err, emitter, log))
|
||||||
.subscribe();
|
.subscribe();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,5 +58,5 @@ export function init(maybeWrapper: Wrapper | 'file') {
|
|||||||
const messages$ = messageHandler(dependencies, wrapper.defaultPrefix);
|
const messages$ = messageHandler(dependencies, wrapper.defaultPrefix);
|
||||||
const interactions$ = interactionHandler(dependencies);
|
const interactions$ = interactionHandler(dependencies);
|
||||||
// listening to the message stream and interaction stream
|
// listening to the message stream and interaction stream
|
||||||
merge(messages$, interactions$).pipe(handleCrash(errorHandler, logger)).subscribe();
|
merge(messages$, interactions$).pipe(handleCrash(errorHandler, dependencies[0], logger)).subscribe();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export type Args = ParseType<{ text: string[]; slash: SlashOptions }>;
|
|||||||
export interface SernEventsMapping {
|
export interface SernEventsMapping {
|
||||||
'module.register': [Payload];
|
'module.register': [Payload];
|
||||||
'module.activate': [Payload];
|
'module.activate': [Payload];
|
||||||
error: [Payload];
|
error: [{ type: PayloadType.Failure; module?: AnyModule; reason: string | Error }];
|
||||||
warning: [Payload];
|
warning: [Payload];
|
||||||
modulesLoaded: [never?];
|
modulesLoaded: [never?];
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ export interface SernEventsMapping {
|
|||||||
export type Payload =
|
export type Payload =
|
||||||
| { type: PayloadType.Success; module: AnyModule }
|
| { type: PayloadType.Success; module: AnyModule }
|
||||||
| { type: PayloadType.Failure; module?: AnyModule; reason: string | Error }
|
| { type: PayloadType.Failure; module?: AnyModule; reason: string | Error }
|
||||||
| { type: PayloadType.Warning; reason: string };
|
| { type: PayloadType.Warning; module: undefined; reason: string };
|
||||||
|
|
||||||
|
|
||||||
export type ReplyOptions = string | Omit<InteractionReplyOptions, 'fetchReply'> | MessageReplyOptions;
|
export type ReplyOptions = string | Omit<InteractionReplyOptions, 'fetchReply'> | MessageReplyOptions;
|
||||||
|
|||||||
Reference in New Issue
Block a user