mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 07:24:53 +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
@@ -9,7 +9,7 @@ import express from "express";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import {
|
||||
ControllerConfig, Address, RequestError,
|
||||
ControllerConfig, Address, ConflictError, NotFoundError,
|
||||
InstanceConfig, SystemInfo, Role, ModPack, AccountUpdateEvent,
|
||||
addPluginConfigFields, renamePermissionPrefix,
|
||||
} from "@clusterio/lib";
|
||||
@@ -254,33 +254,33 @@ describe("controller/src/Controller", function() {
|
||||
it("should error on invalid controller", function() {
|
||||
assert.throws(
|
||||
() => controller.sendRequest(new MockEvent(), Address.fromShorthand({ controlId: 99 })),
|
||||
new RequestError("Target control connection does not exist.")
|
||||
new NotFoundError("Target control connection does not exist.")
|
||||
);
|
||||
});
|
||||
it("should error on invalid instance", function() {
|
||||
assert.throws(
|
||||
() => controller.sendRequest(new MockEvent(), Address.fromShorthand({ instanceId: 99 })),
|
||||
new RequestError("Instance with ID 99 does not exist")
|
||||
new NotFoundError("Instance with ID 99 does not exist")
|
||||
);
|
||||
});
|
||||
it("should error on unassigned instance", function() {
|
||||
mockInstanceConfig.set("instance.assigned_host", null);
|
||||
assert.throws(
|
||||
() => controller.sendRequest(new MockEvent(), Address.fromShorthand({ instanceId: 100 })),
|
||||
new RequestError("Instance is not assigned to a host")
|
||||
new ConflictError("Instance is not assigned to a host")
|
||||
);
|
||||
});
|
||||
it("should error on instance with disconnected host", function() {
|
||||
mockInstanceConfig.set("instance.assigned_host", 99);
|
||||
assert.throws(
|
||||
() => controller.sendRequest(new MockEvent(), Address.fromShorthand({ instanceId: 100 })),
|
||||
new RequestError("Host containing instance is not connected")
|
||||
new ConflictError("Host containing instance is not connected")
|
||||
);
|
||||
});
|
||||
it("should error on invalid host", function() {
|
||||
assert.throws(
|
||||
() => controller.sendRequest(new MockEvent(), Address.fromShorthand({ hostId: 99 })),
|
||||
new RequestError("Host is not connected")
|
||||
new ConflictError("Host is not connected")
|
||||
);
|
||||
});
|
||||
it("should error on invalid broadcast", function() {
|
||||
|
||||
Reference in new issue
Block a user