mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23:04:52 +09:00
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>
25 lines
995 B
JavaScript
25 lines
995 B
JavaScript
"use strict";
|
|
const assert = require("assert").strict;
|
|
|
|
const lib = require("@clusterio/lib");
|
|
|
|
describe("lib/errors", function() {
|
|
describe("class InvalidMessage", function() {
|
|
it("should include validation errors in the stack", function() {
|
|
let errors = [{ instancePath: "/value", message: "must be number" }];
|
|
let err = new lib.InvalidMessage("Request Test failed validation", errors);
|
|
assert.equal(err.message, "Request Test failed validation");
|
|
assert.equal(err.errors, errors);
|
|
assert(err.stack.startsWith("Error: Request Test failed validation\n"));
|
|
assert(err.stack.endsWith(`\n${JSON.stringify(errors, null, "\t")}`));
|
|
});
|
|
it("should leave the stack alone without errors", function() {
|
|
let err = new lib.InvalidMessage("Unrecognized request Test");
|
|
assert.equal(err.errors, undefined);
|
|
assert(!err.stack.includes("\n["));
|
|
let nullErr = new lib.InvalidMessage("Unrecognized request Test", null);
|
|
assert.equal(nullErr.errors, null);
|
|
});
|
|
});
|
|
});
|