Add UnavailableError and keep the PermissionError name

Host not connected, host shutting down and instance not running are
now UnavailableError (503) instead of ConflictError. The request error
migration notes move to a new 2.1 guide, since this ships in 2.1.

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 1c7c00b033
commit 54e9340e61
23 files changed
+78 -66

No files matched your search

+1 -1
View File
@@ -197,7 +197,7 @@ describe("controller/src/ControlConnection", function() {
await connection.handleLogSetSubscriptionsRequest(
new lib.LogSetSubscriptionsRequest(true, false, [], [])
);
connection.user = { checkPermission() { throw new lib.PermissionDeniedError("Permission denied"); } };
connection.user = { checkPermission() { throw new lib.PermissionError("Permission denied"); } };
connection.checkLogPermission();
assert.equal(mockController.clusterLogger.transports.size, 0);
assert.equal(connection.logTransport, null);
+3 -3
View File
@@ -9,7 +9,7 @@ import express from "express";
import { fileURLToPath } from "node:url";
import {
ControllerConfig, Address, ConflictError, NotFoundError,
ControllerConfig, Address, ConflictError, NotFoundError, UnavailableError,
InstanceConfig, SystemInfo, Role, ModPack, AccountUpdateEvent,
addPluginConfigFields, renamePermissionPrefix,
} from "@clusterio/lib";
@@ -274,13 +274,13 @@ describe("controller/src/Controller", function() {
mockInstanceConfig.set("instance.assigned_host", 99);
assert.throws(
() => controller.sendRequest(new MockEvent(), Address.fromShorthand({ instanceId: 100 })),
new ConflictError("Host containing instance is not connected")
new UnavailableError("Host containing instance is not connected")
);
});
it("should error on invalid host", function() {
assert.throws(
() => controller.sendRequest(new MockEvent(), Address.fromShorthand({ hostId: 99 })),
new ConflictError("Host is not connected")
new UnavailableError("Host is not connected")
);
});
it("should error on invalid broadcast", function() {
+2 -2
View File
@@ -172,7 +172,7 @@ describe("controller/InstanceManager", function () {
it("should throw if host not connected", async function () {
await assert.rejects(
() => instances.assignInstance(1, 5),
lib.ConflictError
lib.UnavailableError
);
});
@@ -204,7 +204,7 @@ describe("controller/InstanceManager", function () {
await assert.rejects(
() => instances.assignInstance(1, 6),
lib.ConflictError
lib.UnavailableError
);
assert.equal(unassignRequest, undefined);
+3 -1
View File
@@ -835,7 +835,9 @@ describe("lib/config/classes", function() {
it("should throw if dependent validation fails", function() {
assert.throws(
() => testInstance.set("test.base", 5),
new lib.InvalidValueError("Failed validation of dependent test.dependent: dependent must be >= base")
new lib.InvalidValueError(
"Failed validation of dependent test.dependent: dependent must be >= base"
)
);
assert.deepEqual(TestConfig.validatorCalls, [
["test.dependent", 1], // set test.base
+1 -1
View File
@@ -556,7 +556,7 @@ describe("lib/link/link", function() {
let errored = false;
connector.on("error", () => { errored = true; });
link.handle(SimpleRequest, async () => { handled = true; });
link.validatePermission = () => { throw new lib.PermissionDeniedError("Denied"); };
link.validatePermission = () => { throw new lib.PermissionError("Denied"); };
connector.emit("message", message);
assert(!handled, "handler ran despite denial");
assert(!errored, "connector emitted error on denial");
+6 -6
View File
@@ -560,7 +560,7 @@ describe("lib/subscriptions", function() {
checkPermission(permission) {
if (permission === this.denied) {
throw new lib.PermissionDeniedError("Permission denied");
throw new lib.PermissionError("Permission denied");
}
}
}
@@ -1400,26 +1400,26 @@ describe("lib/subscriptions", function() {
assert.equal(eventSubscriber.synced, true);
mockControl.sendTo = async function() {
throw new lib.PermissionDeniedError("Permission denied");
throw new lib.PermissionError("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.PermissionDeniedError);
assert.ok(eventSubscriber.error instanceof lib.PermissionError);
});
it("should expose errors through the snapshot", async function() {
eventSubscriber.control.sendTo = function() {
throw new lib.PermissionDeniedError("Permission denied");
throw new lib.PermissionError("Permission denied");
};
const unsubscribe = eventSubscriber.subscribe(() => {});
await new Promise(r => setImmediate(r));
const [,, error1] = eventSubscriber.getSnapshot();
assert.ok(error1 instanceof lib.PermissionDeniedError);
assert.ok(error1 instanceof lib.PermissionError);
assert.equal(error1.message, "Permission denied");
assert.equal(lib.Link.errorName(error1), "PermissionDeniedError");
assert.equal(lib.Link.errorName(error1), "PermissionError");
eventSubscriber.control.sendTo = function() {};
unsubscribe();
+2 -2
View File
@@ -83,11 +83,11 @@ describe("messages/note", function() {
it("rejects an empty resource type or id", async function() {
await assert.rejects(
controlConnection.handleNoteSetRequest(new lib.NoteSetRequest("", "1", "text")),
new lib.RequestError("resourceType and resourceId must not be empty"),
new lib.ValidationError("resourceType and resourceId must not be empty"),
);
await assert.rejects(
controlConnection.handleNoteSetRequest(new lib.NoteSetRequest("host", "", "text")),
new lib.RequestError("resourceType and resourceId must not be empty"),
new lib.ValidationError("resourceType and resourceId must not be empty"),
);
});
});