mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 15:33:12 +09:00
Cover the message fallback in Link error logging
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
dc129b2fad
commit
4730faea0c
1 file changed
+35
@@ -432,6 +432,23 @@ describe("lib/link/link", function() {
|
|||||||
));
|
));
|
||||||
assert(logged[0].includes('"message": "must be number"'));
|
assert(logged[0].includes('"message": "must be number"'));
|
||||||
});
|
});
|
||||||
|
it("should fall back to message when event handler error has no stack", async function() {
|
||||||
|
let logged = [];
|
||||||
|
const originalError = lib.logger.error;
|
||||||
|
lib.logger.error = msg => { logged.push(msg); };
|
||||||
|
try {
|
||||||
|
testLink.handle(SimpleEvent, async () => {
|
||||||
|
let err = new Error("no stack");
|
||||||
|
err.stack = undefined;
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
testConnector.emit("message", new lib.MessageEvent(1, dst, src, "SimpleEvent"));
|
||||||
|
await new Promise(resolve => setImmediate(resolve));
|
||||||
|
} finally {
|
||||||
|
lib.logger.error = originalError;
|
||||||
|
}
|
||||||
|
assert.deepEqual(logged, ["Unexpected error handling SimpleEvent:\nno stack"]);
|
||||||
|
});
|
||||||
it("should throw on unknown type", function() {
|
it("should throw on unknown type", function() {
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => testLink.handle({ name: "Bad", type: "bad" }),
|
() => testLink.handle({ name: "Bad", type: "bad" }),
|
||||||
@@ -634,6 +651,24 @@ describe("lib/link/link", function() {
|
|||||||
));
|
));
|
||||||
assert(logged[0].includes('"message": "must be number"'));
|
assert(logged[0].includes('"message": "must be number"'));
|
||||||
});
|
});
|
||||||
|
it("should fall back to message when snoop handler error has no stack", async function() {
|
||||||
|
let logged = [];
|
||||||
|
const originalError = lib.logger.error;
|
||||||
|
lib.logger.error = msg => { logged.push(msg); };
|
||||||
|
try {
|
||||||
|
testLink.handle(SimpleEvent, async () => {});
|
||||||
|
testLink.snoopEvent(SimpleEvent, async () => {
|
||||||
|
let err = new Error("no stack");
|
||||||
|
err.stack = undefined;
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
testConnector.emit("message", new lib.MessageEvent(1, dst, src, "SimpleEvent"));
|
||||||
|
await new Promise(resolve => setImmediate(resolve));
|
||||||
|
} finally {
|
||||||
|
lib.logger.error = originalError;
|
||||||
|
}
|
||||||
|
assert.deepEqual(logged, ["Unexpected error snooping SimpleEvent:\nno stack"]);
|
||||||
|
});
|
||||||
it("should throw on double registration", function() {
|
it("should throw on double registration", function() {
|
||||||
testLink.snoopEvent(SimpleEvent);
|
testLink.snoopEvent(SimpleEvent);
|
||||||
assert.throws(
|
assert.throws(
|
||||||
|
|||||||
Reference in new issue
Block a user