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:
bbassieandClaude Opus 5.5 committed 2026-10-27 22:03:13 +00:00
1 parent ffe82f81d8
commit 1c7c00b033
37 files changed
+589 -310

No files matched your search

+3 -2
View File
@@ -37,8 +37,8 @@ describe("host/src/Host", function() {
describe("class HostRouter", function() {
describe(".wakeInstance()", function() {
it("should log the message of a start error that has no stack", async function() {
// RequestError leaves its stack undefined
const err = new lib.RequestError("No available port left to assign from host.factorio_port_range");
const err = new lib.ConflictError("No available port left to assign from host.factorio_port_range");
err.stack = undefined;
const mockHost = {
_shuttingDown: false,
_connectInstance: async () => { throw err; },
@@ -57,6 +57,7 @@ describe("host/src/Host", function() {
lib.logger.error = originalError;
}
assert.equal(responses.length, 1);
assert.equal(responses[0].code, "ConflictError");
assert.equal(logged.length, 1);
assert.match(logged[0], /No available port left to assign/);
});
+4 -4
View File
@@ -284,11 +284,11 @@ describe("class Instance", function() {
instance.server.version = "1.1.91";
assert.throws(
() => instance.checkModPackVersion(modPack("1.1.110")),
new lib.RequestError(
new lib.ConflictError(
"Mod pack pack is for Factorio 1.1.110 which is newer than the Factorio 1.1.91 this instance runs"
)
);
assert.throws(() => instance.checkModPackVersion(modPack("2.0")), lib.RequestError);
assert.throws(() => instance.checkModPackVersion(modPack("2.0")), lib.ConflictError);
});
it("should skip the check when the server version is unknown", function() {
@@ -300,7 +300,7 @@ describe("class Instance", function() {
it("should reject a start save outside the saves directory", async function() {
await assert.rejects(
instance.handleInstanceStartRequest(new lib.InstanceStartRequest("../escape.zip")),
lib.RequestError,
lib.ValidationError,
);
});
it("should reject a created save outside the saves directory", async function() {
@@ -308,7 +308,7 @@ describe("class Instance", function() {
instance.handleInstanceCreateSaveRequest(
new lib.InstanceCreateSaveRequest("../escape.zip"),
),
lib.RequestError,
lib.ValidationError,
);
});
});