mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 23:33:13 +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
@@ -139,7 +139,7 @@ describe("controller/src/ControlConnection", function() {
|
||||
it("rejects instance.assigned_host in the config", async function() {
|
||||
await assert.rejects(
|
||||
create({ "instance.id": 4001, "instance.name": "c1", "instance.assigned_host": 10 }),
|
||||
new lib.RequestError("instance.assigned_host must be set through the assign-host interface"),
|
||||
new lib.ValidationError("instance.assigned_host must be set through the assign-host interface"),
|
||||
);
|
||||
assert.equal(mockController.instances.has(4001), false);
|
||||
});
|
||||
@@ -197,7 +197,7 @@ describe("controller/src/ControlConnection", function() {
|
||||
await connection.handleLogSetSubscriptionsRequest(
|
||||
new lib.LogSetSubscriptionsRequest(true, false, [], [])
|
||||
);
|
||||
connection.user = { checkPermission() { throw new lib.PermissionError("Permission denied"); } };
|
||||
connection.user = { checkPermission() { throw new lib.PermissionDeniedError("Permission denied"); } };
|
||||
connection.checkLogPermission();
|
||||
assert.equal(mockController.clusterLogger.transports.size, 0);
|
||||
assert.equal(connection.logTransport, null);
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -101,7 +101,7 @@ describe("controller/InstanceManager", function () {
|
||||
});
|
||||
|
||||
it("should throw when missing", function () {
|
||||
assert.throws(() => instances.getForRequest(999), lib.RequestError);
|
||||
assert.throws(() => instances.getForRequest(999), lib.NotFoundError);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -148,7 +148,7 @@ describe("controller/InstanceManager", function () {
|
||||
|
||||
await assert.rejects(
|
||||
() => instances.createInstance(config),
|
||||
lib.RequestError
|
||||
lib.ConflictError
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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.RequestError
|
||||
lib.ConflictError
|
||||
);
|
||||
});
|
||||
|
||||
@@ -204,7 +204,7 @@ describe("controller/InstanceManager", function () {
|
||||
|
||||
await assert.rejects(
|
||||
() => instances.assignInstance(1, 6),
|
||||
lib.RequestError
|
||||
lib.ConflictError
|
||||
);
|
||||
|
||||
assert.equal(unassignRequest, undefined);
|
||||
@@ -312,7 +312,7 @@ describe("controller/InstanceManager", function () {
|
||||
controller.wsServer.hostConnections.set(6, {
|
||||
send: async (request) => {
|
||||
if (failAssign) {
|
||||
throw new lib.RequestError("EACCES: permission denied");
|
||||
throw new lib.InternalServerError("EACCES: permission denied");
|
||||
}
|
||||
assignRequest = request;
|
||||
},
|
||||
|
||||
@@ -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/);
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -744,7 +744,7 @@ describe("Integration of Clusterio", function() {
|
||||
slowTest(this);
|
||||
await assert.rejects(
|
||||
execCtl("instance create testClone --id 440 --from 441"),
|
||||
new lib.RequestError("Instance with ID 441 does not exist")
|
||||
new lib.NotFoundError("Instance with ID 441 does not exist")
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
+17
-17
@@ -652,14 +652,14 @@ describe("lib/config/classes", function() {
|
||||
let testInstance = new TestConfig("local");
|
||||
assert.throws(
|
||||
() => testInstance.get("test.priv", "remote"),
|
||||
new lib.InvalidAccess("Field 'test.priv' is not accessible from remote")
|
||||
new lib.InvalidAccessError("Field 'test.priv' is not accessible from remote")
|
||||
);
|
||||
});
|
||||
it("should throw if field is locally inaccessible", function() {
|
||||
let testInstance = new TestConfig("remote");
|
||||
assert.throws(
|
||||
() => testInstance.get("test.priv"),
|
||||
new lib.InvalidAccess("Field 'test.priv' is not accessible from remote")
|
||||
new lib.InvalidAccessError("Field 'test.priv' is not accessible from remote")
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -677,20 +677,20 @@ describe("lib/config/classes", function() {
|
||||
it("should throw if field does not exist", function() {
|
||||
assert.throws(
|
||||
() => set("test.bar", 1),
|
||||
new lib.InvalidField("No field named 'test.bar'")
|
||||
new lib.InvalidFieldError("No field named 'test.bar'")
|
||||
);
|
||||
});
|
||||
it("should throw if field is remotely inaccessible", function() {
|
||||
assert.throws(
|
||||
() => set("test.priv", "bad", "remote"),
|
||||
new lib.InvalidAccess("Field 'test.priv' is not accessible from remote")
|
||||
new lib.InvalidAccessError("Field 'test.priv' is not accessible from remote")
|
||||
);
|
||||
});
|
||||
it("should throw if field is locally inaccessible", function() {
|
||||
replaceConfig(new TestConfig("remote"));
|
||||
assert.throws(
|
||||
() => set("test.priv", "bad", "local"),
|
||||
new lib.InvalidAccess("Field 'test.priv' is not accessible from remote")
|
||||
new lib.InvalidAccessError("Field 'test.priv' is not accessible from remote")
|
||||
);
|
||||
});
|
||||
it("should throw if field is not in enum", function() {
|
||||
@@ -731,7 +731,7 @@ describe("lib/config/classes", function() {
|
||||
|
||||
assert.throws(
|
||||
() => set("test.bool", "blah"),
|
||||
new lib.InvalidValue("Expected type of test.bool to be boolean, not string")
|
||||
new lib.InvalidValueError("Expected type of test.bool to be boolean, not string")
|
||||
);
|
||||
});
|
||||
it("should auto convert string to number if possible", function() {
|
||||
@@ -749,7 +749,7 @@ describe("lib/config/classes", function() {
|
||||
|
||||
assert.throws(
|
||||
() => set("test.func", "blah"),
|
||||
new lib.InvalidValue("Expected type of test.func to be number, not string")
|
||||
new lib.InvalidValueError("Expected type of test.func to be number, not string")
|
||||
);
|
||||
});
|
||||
it("should auto convert string to object", function() {
|
||||
@@ -764,7 +764,7 @@ describe("lib/config/classes", function() {
|
||||
}
|
||||
assert.throws(
|
||||
() => set("test.json", "blah"),
|
||||
new lib.InvalidValue(`Error parsing value for test.json: ${errMsg}`)
|
||||
new lib.InvalidValueError(`Error parsing value for test.json: ${errMsg}`)
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -815,7 +815,7 @@ describe("lib/config/classes", function() {
|
||||
it("should throw if validator fails", function() {
|
||||
assert.throws(
|
||||
() => testInstance.set("test.validated", -1),
|
||||
new lib.InvalidValue("Failed validation of test.validated: must be positive")
|
||||
new lib.InvalidValueError("Failed validation of test.validated: must be positive")
|
||||
);
|
||||
assert.deepEqual(TestConfig.validatorCalls, [
|
||||
["test.validated", -1], // set test.validated
|
||||
@@ -835,7 +835,7 @@ describe("lib/config/classes", function() {
|
||||
it("should throw if dependent validation fails", function() {
|
||||
assert.throws(
|
||||
() => testInstance.set("test.base", 5),
|
||||
new lib.InvalidValue("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
|
||||
@@ -853,26 +853,26 @@ describe("lib/config/classes", function() {
|
||||
it("should throw if field does not exist", function() {
|
||||
assert.throws(
|
||||
() => setProp("test.bar", 1),
|
||||
new lib.InvalidField("No field named 'test.bar'")
|
||||
new lib.InvalidFieldError("No field named 'test.bar'")
|
||||
);
|
||||
});
|
||||
it("should throw if field is remotely inaccessible", function() {
|
||||
assert.throws(
|
||||
() => setProp("test.priv", "prop", "bad", "remote"),
|
||||
new lib.InvalidAccess("Field 'test.priv' is not accessible from remote")
|
||||
new lib.InvalidAccessError("Field 'test.priv' is not accessible from remote")
|
||||
);
|
||||
});
|
||||
it("should throw if field is locally inaccessible", function() {
|
||||
replaceConfig(new TestConfig("remote"));
|
||||
assert.throws(
|
||||
() => setProp("test.priv", "prop", "bad", "local"),
|
||||
new lib.InvalidAccess("Field 'test.priv' is not accessible from remote")
|
||||
new lib.InvalidAccessError("Field 'test.priv' is not accessible from remote")
|
||||
);
|
||||
});
|
||||
it("should throw if field is not an object", function() {
|
||||
assert.throws(
|
||||
() => setProp("test.enum", "prop", "a"),
|
||||
new lib.InvalidField("Cannot set property on non-object field 'test.enum'")
|
||||
new lib.InvalidFieldError("Cannot set property on non-object field 'test.enum'")
|
||||
);
|
||||
});
|
||||
it("should work if field is an object", function() {
|
||||
@@ -939,7 +939,7 @@ describe("lib/config/classes", function() {
|
||||
it("should throw if object validator fails", function() {
|
||||
assert.throws(
|
||||
() => testInstance.setProp("test.objValidated", "bad", true),
|
||||
new lib.InvalidValue("Failed validation of test.objValidated: bad key")
|
||||
new lib.InvalidValueError("Failed validation of test.objValidated: bad key")
|
||||
);
|
||||
assert.deepEqual(TestConfig.validatorCalls, [
|
||||
["test.objValidated", { bad: true }], // setProp test.objValidated bad
|
||||
@@ -957,7 +957,7 @@ describe("lib/config/classes", function() {
|
||||
testInstance.set("test.base", 0);
|
||||
assert.throws(
|
||||
() => testInstance.setProp("test.objDependent", "base", 0),
|
||||
new lib.InvalidValue("Failed validation of dependent test.dependent: objDependent cannot be 0")
|
||||
new lib.InvalidValueError("Failed validation of dependent test.dependent: objDependent cannot be 0")
|
||||
);
|
||||
assert.deepEqual(TestConfig.validatorCalls, [
|
||||
["test.dependent", 1], // set test.base
|
||||
@@ -1065,7 +1065,7 @@ describe("lib/config/classes", function() {
|
||||
|
||||
assert.throws(
|
||||
() => testInstance.commitStaging(),
|
||||
new lib.InvalidValue("Failed validation of test.validated: must be positive")
|
||||
new lib.InvalidValueError("Failed validation of test.validated: must be positive")
|
||||
);
|
||||
assert.deepEqual(TestConfig.validatorCalls, [
|
||||
// commitStaging, all values are checked once
|
||||
|
||||
@@ -10,11 +10,11 @@ describe("lib/data/messages_user", function() {
|
||||
return { checked, checkPermission(permission) { checked.push(permission); } };
|
||||
}
|
||||
|
||||
it("should deny an unknown importType with a PermissionError", function() {
|
||||
it("should deny an unknown importType with a ValidationError", function() {
|
||||
const user = grantAllUser();
|
||||
assert.throws(
|
||||
() => lib.UserBulkImportRequest.permission(user, { data: { importType: "foo", users: [] } }),
|
||||
lib.PermissionError,
|
||||
lib.ValidationError,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
+109
-6
@@ -345,7 +345,7 @@ describe("lib/link/link", function() {
|
||||
assert.deepEqual(
|
||||
await message,
|
||||
[new lib.MessageResponseError(
|
||||
1, src, dst, new lib.ResponseError("Error", undefined, "Error")
|
||||
1, src, dst, new lib.ResponseError("Error", "InternalServerError", "Error")
|
||||
)]
|
||||
);
|
||||
});
|
||||
@@ -361,7 +361,7 @@ describe("lib/link/link", function() {
|
||||
1, src, dst,
|
||||
new lib.ResponseError(
|
||||
"Request NumberRequest failed validation",
|
||||
response.data.code,
|
||||
"InvalidMessage",
|
||||
response.data.stack,
|
||||
)
|
||||
)
|
||||
@@ -550,20 +550,20 @@ describe("lib/link/link", function() {
|
||||
return { connector, link, message };
|
||||
}
|
||||
|
||||
it("should silently deny on PermissionError from the permission check", function() {
|
||||
it("should silently deny on ClientError from the permission check", function() {
|
||||
const { connector, link, message } = controlSetup();
|
||||
let handled = false;
|
||||
let errored = false;
|
||||
connector.on("error", () => { errored = true; });
|
||||
link.handle(SimpleRequest, async () => { handled = true; });
|
||||
link.validatePermission = () => { throw new lib.PermissionError("Denied"); };
|
||||
link.validatePermission = () => { throw new lib.PermissionDeniedError("Denied"); };
|
||||
connector.emit("message", message);
|
||||
assert(!handled, "handler ran despite denial");
|
||||
assert(!errored, "connector emitted error on denial");
|
||||
assert.deepEqual(connector.sentMessages, [], "denial sent a message");
|
||||
});
|
||||
|
||||
it("should not crash when the permission check throws a non-PermissionError", function() {
|
||||
it("should not crash when the permission check throws a non-ClientError", function() {
|
||||
const { connector, link, message } = controlSetup();
|
||||
let handled = false;
|
||||
let errored = false;
|
||||
@@ -578,7 +578,7 @@ describe("lib/link/link", function() {
|
||||
} finally {
|
||||
lib.logger.error = originalError;
|
||||
}
|
||||
assert(!errored, "non-PermissionError escaped to the connector error path");
|
||||
assert(!errored, "non-ClientError escaped to the connector error path");
|
||||
assert(!handled, "handler ran after the permission check threw");
|
||||
assert.equal(logged.length, 1);
|
||||
assert(logged[0].startsWith("Unexpected error checking permission for SimpleRequest:\n"));
|
||||
@@ -664,6 +664,109 @@ describe("lib/link/link", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Error responses", function() {
|
||||
class ErrorTestRequest {
|
||||
static type = "request";
|
||||
static src = "control";
|
||||
static dst = "host";
|
||||
static permission = null;
|
||||
}
|
||||
lib.Link.register(ErrorTestRequest);
|
||||
class TestPluginError extends lib.ConflictError {
|
||||
static plugin = "error_test";
|
||||
}
|
||||
lib.registerPluginMessages([{ name: "error_test", errors: [TestPluginError] }]);
|
||||
|
||||
// control 1 <-> controller <-> host 1, with the controller forwarding between the two
|
||||
function forwardingSetup() {
|
||||
const [clientConnector, controlConnector] = lib.VirtualConnector.makePair(
|
||||
addr({ controlId: 1 }), addr("controller")
|
||||
);
|
||||
const [hostSideConnector, hostConnector] = lib.VirtualConnector.makePair(
|
||||
addr("controller"), addr({ hostId: 1 })
|
||||
);
|
||||
const client = new lib.Link(clientConnector);
|
||||
const controlSide = new lib.Link(controlConnector);
|
||||
const hostSide = new lib.Link(hostSideConnector);
|
||||
const host = new lib.Link(hostConnector);
|
||||
controlSide.router = { forwardMessage(origin, message) {
|
||||
hostSide.forwardRequest(message, origin);
|
||||
return true;
|
||||
} };
|
||||
hostSide.router = { forwardMessage(origin, message) {
|
||||
controlSide.connector.forward(message);
|
||||
return true;
|
||||
} };
|
||||
return { client, host };
|
||||
}
|
||||
|
||||
async function rejectionFor(err) {
|
||||
const { client, host } = forwardingSetup();
|
||||
host.handle(ErrorTestRequest, async () => { throw err; });
|
||||
const logged = [];
|
||||
const originalError = lib.logger.error;
|
||||
lib.logger.error = msg => { logged.push(msg); };
|
||||
try {
|
||||
await client.sendTo({ hostId: 1 }, new ErrorTestRequest());
|
||||
} catch (received) {
|
||||
return { received, logged };
|
||||
} finally {
|
||||
lib.logger.error = originalError;
|
||||
}
|
||||
throw new Error("Request did not reject");
|
||||
}
|
||||
|
||||
it("should reject with the class thrown by the handler", async function() {
|
||||
const err = new lib.NotFoundError("Thing does not exist");
|
||||
const { received, logged } = await rejectionFor(err);
|
||||
assert(received instanceof lib.NotFoundError);
|
||||
assert.equal(received.message, "Thing does not exist");
|
||||
assert.equal(received.stack, err.stack);
|
||||
assert.deepEqual(logged, []);
|
||||
});
|
||||
it("should reject with a registered plugin error class", async function() {
|
||||
const { received, logged } = await rejectionFor(new TestPluginError("Plugin conflict"));
|
||||
assert(received instanceof TestPluginError);
|
||||
assert.equal(received.message, "Plugin conflict");
|
||||
assert.deepEqual(logged, []);
|
||||
});
|
||||
it("should reject with the closest registered class of an unregistered error", async function() {
|
||||
class UnregisteredError extends lib.ConflictError { }
|
||||
const { received } = await rejectionFor(new UnregisteredError("Busy"));
|
||||
assert.equal(received.constructor, lib.ConflictError);
|
||||
});
|
||||
it("should reject with InternalServerError and log for unregistered errors", async function() {
|
||||
const err = new TypeError("x is not a function");
|
||||
const { received, logged } = await rejectionFor(err);
|
||||
assert(received instanceof lib.InternalServerError);
|
||||
assert.equal(received.message, "x is not a function");
|
||||
assert.equal(received.stack, err.stack);
|
||||
assert.equal(logged.length, 1);
|
||||
assert(logged[0].startsWith("Unexpected error responding to ErrorTestRequest:\n"));
|
||||
});
|
||||
it("should reject with InternalServerError for an unknown error name", async function() {
|
||||
const received = lib.Link.errorFromResponse(new lib.ResponseError("Gone", "other_plugin:GoneError"));
|
||||
assert(received instanceof lib.InternalServerError);
|
||||
assert.equal(received.message, "Gone");
|
||||
});
|
||||
it("should require plugin errors to set the plugin property", function() {
|
||||
class MissingPluginError extends lib.ClientError { }
|
||||
assert.throws(
|
||||
() => lib.registerPluginMessages([{ name: "error_test_2", errors: [MissingPluginError] }]),
|
||||
new Error(
|
||||
"Expected error MissingPluginError from error_test_2 to have a static plugin property " +
|
||||
"set to \"error_test_2\""
|
||||
)
|
||||
);
|
||||
});
|
||||
it("should throw when registering an error name twice", function() {
|
||||
assert.throws(
|
||||
() => lib.Link.registerError(lib.NotFoundError),
|
||||
new Error("Error NotFoundError is already registered")
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe(".snoopEvent()", function() {
|
||||
it("should snoop an event", function() {
|
||||
let handled = false;
|
||||
|
||||
@@ -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