mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 07:43:12 +09:00
Keep error classes across links
Error responses now carry the registered name of the thrown error's class, and the requester rejects with an instance of that class instead of a generic RequestError. Error classes are registered like message classes, and plugins list their own in `errors`. RequestError is replaced by a hierarchy following the HTTP status codes: ClientError (ValidationError, ForbiddenError, NotFoundError, TimeoutError, ConflictError) and ServerError (InternalServerError). PermissionError is PermissionDeniedError and the config errors InvalidValue, InvalidField and InvalidAccess gain an Error suffix. Link logs only errors whose class is not registered. These arrive on the other side as InternalServerError with the original message and stack, so an error forwarded through the controller is logged once, where it was thrown. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ffe82f81d8
commit
1c7c00b033
37 files changed
+589
-310
No files matched your search
@@ -560,7 +560,7 @@ describe("lib/subscriptions", function() {
|
||||
|
||||
checkPermission(permission) {
|
||||
if (permission === this.denied) {
|
||||
throw new lib.PermissionError("Permission denied");
|
||||
throw new lib.PermissionDeniedError("Permission denied");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -794,7 +794,7 @@ describe("lib/subscriptions", function() {
|
||||
const request1 = new lib.SubscriptionRequest(RegisteredEvent.name, "subscribe", 0, "baz");
|
||||
await assert.rejects(
|
||||
ownSubscriptions.handleRequest(link, request1, connectorData.dst, connectorData.src),
|
||||
lib.RequestError,
|
||||
lib.ValidationError,
|
||||
);
|
||||
|
||||
ownSubscriptions.broadcast(new RegisteredEvent(), "baz");
|
||||
@@ -973,7 +973,7 @@ describe("lib/subscriptions", function() {
|
||||
);
|
||||
await assert.rejects(
|
||||
ownSubscriptions.handleRequest(link, request, connectorData.dst, connectorData.src),
|
||||
lib.RequestError,
|
||||
lib.ValidationError,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1371,15 +1371,13 @@ describe("lib/subscriptions", function() {
|
||||
assert.notEqual(logged, undefined);
|
||||
});
|
||||
|
||||
it("should not log error when sendTo throws SessionLost RequestError", async function() {
|
||||
it("should not log error when sendTo throws SessionLost", async function() {
|
||||
let logged;
|
||||
const originalError = lib.logger.error;
|
||||
lib.logger.error = msg => { logged = msg; };
|
||||
|
||||
mockControl.sendTo = async function() {
|
||||
const err = new lib.RequestError("Session lost");
|
||||
err.code = "SessionLost";
|
||||
throw err;
|
||||
throw new lib.SessionLost("Session lost");
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -1402,26 +1400,26 @@ describe("lib/subscriptions", function() {
|
||||
assert.equal(eventSubscriber.synced, true);
|
||||
|
||||
mockControl.sendTo = async function() {
|
||||
throw new lib.PermissionError("Permission denied");
|
||||
throw new lib.PermissionDeniedError("Permission denied");
|
||||
};
|
||||
eventSubscriber.handleAccountEvent();
|
||||
await new Promise(r => setImmediate(r));
|
||||
assert.equal(eventSubscriber.synced, false);
|
||||
assert.deepEqual(calledWith, [null, false]);
|
||||
assert.ok(eventSubscriber.error instanceof lib.PermissionError);
|
||||
assert.ok(eventSubscriber.error instanceof lib.PermissionDeniedError);
|
||||
});
|
||||
|
||||
it("should expose errors through the snapshot", async function() {
|
||||
eventSubscriber.control.sendTo = function() {
|
||||
throw new lib.PermissionError("Permission denied");
|
||||
throw new lib.PermissionDeniedError("Permission denied");
|
||||
};
|
||||
|
||||
const unsubscribe = eventSubscriber.subscribe(() => {});
|
||||
await new Promise(r => setImmediate(r));
|
||||
const [,, error1] = eventSubscriber.getSnapshot();
|
||||
assert.ok(error1 instanceof lib.PermissionError);
|
||||
assert.ok(error1 instanceof lib.PermissionDeniedError);
|
||||
assert.equal(error1.message, "Permission denied");
|
||||
assert.equal(error1.code, "PermissionError");
|
||||
assert.equal(lib.Link.errorName(error1), "PermissionDeniedError");
|
||||
|
||||
eventSubscriber.control.sendTo = function() {};
|
||||
unsubscribe();
|
||||
|
||||
Reference in new issue
Block a user