mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 23:33:13 +09:00
Include schema validation errors in InvalidMessage stack
Generic error handlers such as FactorioServer.handle() and the event handler catch in Link only log err.stack, so the ajv errors attached to an InvalidMessage were lost unless the catch site checked for the class explicitly. Appending the errors to the stack in the constructor makes every stack-logging handler show which field failed validation without special casing each one. Fixes #986 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
abfc5ff8d5
commit
dc129b2fad
5 files changed
+95
-2
No files matched your search
@@ -58,6 +58,10 @@ export class InvalidMessage extends Error {
|
||||
public errors?: object | null,
|
||||
) {
|
||||
super(message);
|
||||
// Include the errors in the stack so generic handlers logging it show what failed
|
||||
if (errors) {
|
||||
this.stack += `\n${JSON.stringify(errors, null, "\t")}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ export class Link {
|
||||
let handler = this._eventSnoopers.get((entry as EventEntry).Event)!;
|
||||
let event = message as libData.MessageEvent;
|
||||
handler((entry as EventEntry).eventFromJSON(event.data), event.src, event.dst).catch((err: Error) => {
|
||||
logger.error(`Unexpected error snooping ${event.name}:\n${err.stack}`);
|
||||
logger.error(`Unexpected error snooping ${event.name}:\n${err.stack ?? err.message}`);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -482,7 +482,7 @@ export class Link {
|
||||
handler(
|
||||
entry.eventFromJSON(message.data), message.src, message.dst
|
||||
).catch((err: Error) => {
|
||||
logger.error(`Unexpected error handling ${message.name}:\n${err.stack}`);
|
||||
logger.error(`Unexpected error handling ${message.name}:\n${err.stack ?? err.message}`);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user