mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 08:03:13 +09:00
Improve link error messages
Reverse the reversal of source/target in message errors and add link source and target to the error given when a validator is missing on a link.
This commit is contained in:
1 parent
b24778dce6
commit
47cff048f0
4 files changed
+8
-8
No files matched your search
+2
-2
@@ -62,7 +62,7 @@ class Link {
|
|||||||
|
|
||||||
let validator = this._validators.get(message.type);
|
let validator = this._validators.get(message.type);
|
||||||
if (!validator) {
|
if (!validator) {
|
||||||
throw new errors.InvalidMessage(`No validator for ${message.type}`);
|
throw new errors.InvalidMessage(`No validator for ${message.type} on ${this.source}-${this.target}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!validator(message)) {
|
if (!validator(message)) {
|
||||||
@@ -180,7 +180,7 @@ class Link {
|
|||||||
*/
|
*/
|
||||||
async waitFor(type, data) {
|
async waitFor(type, data) {
|
||||||
if (!this._validators.has(type)) {
|
if (!this._validators.has(type)) {
|
||||||
throw new Error(`no validator for ${type}`);
|
throw new Error(`No validator for ${type} on ${this.source}-${this.target}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ class Request {
|
|||||||
// Target side. Note: Source and target is reversed here.
|
// Target side. Note: Source and target is reversed here.
|
||||||
if (this.links.includes(`${link.target}-${link.source}`)) {
|
if (this.links.includes(`${link.target}-${link.source}`)) {
|
||||||
if (!handler) {
|
if (!handler) {
|
||||||
throw new Error(`Missing handler for ${this.requestType} on ${link.target}-${link.source} link`);
|
throw new Error(`Missing handler for ${this.requestType} on ${link.source}-${link.target} link`);
|
||||||
}
|
}
|
||||||
|
|
||||||
link.setHandler(this.requestType, message => {
|
link.setHandler(this.requestType, message => {
|
||||||
@@ -361,7 +361,7 @@ class Event {
|
|||||||
// Target side. Note: Source and target is reversed here.
|
// Target side. Note: Source and target is reversed here.
|
||||||
if (this.links.includes(`${link.target}-${link.source}`)) {
|
if (this.links.includes(`${link.target}-${link.source}`)) {
|
||||||
if (!handler) {
|
if (!handler) {
|
||||||
throw new Error(`Missing handler for ${this.eventType} on ${link.target}-${link.source} link`);
|
throw new Error(`Missing handler for ${this.eventType} on ${link.source}-${link.target} link`);
|
||||||
}
|
}
|
||||||
|
|
||||||
link.setHandler(this.eventType, message => {
|
link.setHandler(this.eventType, message => {
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ describe("lib/link/link", function() {
|
|||||||
it("should throw on message without validator", function() {
|
it("should throw on message without validator", function() {
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => testLink.processMessage({ seq: 1, type: 'no_validator', data: {} }),
|
() => testLink.processMessage({ seq: 1, type: 'no_validator', data: {} }),
|
||||||
new errors.InvalidMessage("No validator for no_validator")
|
new errors.InvalidMessage("No validator for no_validator on source-target")
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it("should throw on message failing validation", function() {
|
it("should throw on message failing validation", function() {
|
||||||
@@ -134,7 +134,7 @@ describe("lib/link/link", function() {
|
|||||||
it("should throw on missing validator", async function() {
|
it("should throw on missing validator", async function() {
|
||||||
await assert.rejects(
|
await assert.rejects(
|
||||||
testLink.waitFor('no_validator', {}),
|
testLink.waitFor('no_validator', {}),
|
||||||
new Error("no validator for no_validator")
|
new Error("No validator for no_validator on source-target")
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it("should wait for a given message", async function() {
|
it("should wait for a given message", async function() {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ describe("lib/link/messages", function() {
|
|||||||
it("should throw if missing handler on target link", function() {
|
it("should throw if missing handler on target link", function() {
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => testRequest.attach(testTargetLink),
|
() => testRequest.attach(testTargetLink),
|
||||||
new Error("Missing handler for test_request on source-target link")
|
new Error("Missing handler for test_request on target-source link")
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ describe("lib/link/messages", function() {
|
|||||||
it("should throw if missing handler on target link", function() {
|
it("should throw if missing handler on target link", function() {
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => testEvent.attach(testTargetLink),
|
() => testEvent.attach(testTargetLink),
|
||||||
new Error("Missing handler for test_event on source-target link")
|
new Error("Missing handler for test_event on target-source link")
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
let called = false;
|
let called = false;
|
||||||
|
|||||||
Reference in new issue
Block a user