Improve error reporting of CommandException

This commit is contained in:
gnuxie committed 2023-05-30 11:14:49 +01:00
1 parent 8e1f930240
commit 006ba3dd1e
2 files changed
+11 -4

No files matched your search

-1
View File
@@ -141,7 +141,6 @@ export async function handleCommand(roomId: string, event: { content: { body: st
return await adaptor.invoke(mjolnirContext, mjolnirContext, ...stream.rest());
} catch (e) {
const commandError = new CommandException(e, 'Unknown Unexpected Error');
LogService.error("CommandHandler", commandError.uuid, commandError.message, e);
await tickCrossRenderer.call(mjolnirContext, mjolnir.client, roomId, event, CommandResult.Err(commandError));
}
}
@@ -11,6 +11,7 @@ import { JSXFactory } from "./JSXFactory";
import { DocumentNode } from "./DeadDocument";
import { renderMatrixAndSend } from "./DeadDocumentMatrix";
import { CommandException } from "./CommandException";
import { LogService } from "matrix-bot-sdk";
function requiredArgument(argumentName: string): string {
return `<${argumentName}>`;
@@ -73,12 +74,15 @@ export async function renderHelp(client: MatrixSendClient, commandRoomId: string
export async function tickCrossRenderer(this: MatrixInterfaceAdaptor<MatrixContext, BaseFunction>, client: MatrixSendClient, commandRoomId: string, event: any, result: CommandResult<unknown, CommandError>): Promise<void> {
const react = async (emote: string) => {
await client.unstableApis.addReactionToEvent(commandRoomId, event['event_id'], emote);
try {
await client.unstableApis.addReactionToEvent(commandRoomId, event['event_id'], emote);
} catch (e) {
LogService.error("tickCrossRenderer", "Couldn't react to the event", event['event_id'], e);
}
}
if (result.isOk()) {
await react('✅')
} else {
await react('❌');
if (result.err instanceof ArgumentParseError) {
await renderMatrixAndSend(
renderArgumentParseError(this.interfaceCommand, result.err),
@@ -86,6 +90,8 @@ export async function tickCrossRenderer(this: MatrixInterfaceAdaptor<MatrixConte
event,
client);
} else if (result.err instanceof CommandException) {
const commandError = result.err;
LogService.error("CommandException", commandError.uuid, commandError.message, commandError.exception);
await renderMatrixAndSend(
renderCommandException(this.interfaceCommand, result.err),
commandRoomId,
@@ -94,6 +100,8 @@ export async function tickCrossRenderer(this: MatrixInterfaceAdaptor<MatrixConte
} else {
await client.replyNotice(commandRoomId, event, result.err.message);
}
// reacting is way less important than communicating what happened, do it last.
await react('❌');
}
}
@@ -133,4 +141,4 @@ function renderCommandException(command: InterfaceCommand<BaseFunction>, error:
export function renderMentionPill(mxid: string, displayName: string): DocumentNode {
const url = `https://matrix.to/#/${mxid}`;
return <a href={url}>{displayName}</a>
}
}