diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-01-25 18:44:49 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-25 18:44:49 -0500 |
commit | 5215c6b8b476d491f324ad3a285bdf6b66a5de41 (patch) | |
tree | 4925fe964c6e1b4c2b0adde1666f79bae3982fbc /ext/mixed/js/comm.js | |
parent | a14ff8f8cde2ea139c15fc79eee48791bd4a7641 (diff) |
Update comm message errors to include what the action was (#1312)
Diffstat (limited to 'ext/mixed/js/comm.js')
-rw-r--r-- | ext/mixed/js/comm.js | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/ext/mixed/js/comm.js b/ext/mixed/js/comm.js index 4a6786c3..ea450da6 100644 --- a/ext/mixed/js/comm.js +++ b/ext/mixed/js/comm.js @@ -43,19 +43,27 @@ class CrossFrameAPIPort extends EventDispatcher { invoke(action, params, ackTimeout, responseTimeout) { return new Promise((resolve, reject) => { if (this._port === null) { - reject(new Error('Port is disconnected')); + reject(new Error(`Port is disconnected (${action})`)); return; } const id = this._invocationId++; - const invocation = {id, resolve, reject, responseTimeout, ack: false, timer: null}; + const invocation = { + id, + resolve, + reject, + responseTimeout, + action, + ack: false, + timer: null + }; this._activeInvocations.set(id, invocation); if (ackTimeout !== null) { try { - invocation.timer = setTimeout(() => this._onError(id, new Error('Timeout (ack)')), ackTimeout); + invocation.timer = setTimeout(() => this._onError(id, 'Acknowledgement timeout'), ackTimeout); } catch (e) { - this._onError(id, new Error('Failed to set timeout')); + this._onError(id, 'Failed to set timeout'); return; } } @@ -79,7 +87,7 @@ class CrossFrameAPIPort extends EventDispatcher { this._eventListeners.removeAllEventListeners(); this._port = null; for (const id of this._activeInvocations.keys()) { - this._onError(id, new Error('Disconnected')); + this._onError(id, 'Disconnected'); } this.trigger('disconnect', this); } @@ -103,12 +111,12 @@ class CrossFrameAPIPort extends EventDispatcher { _onAck(id) { const invocation = this._activeInvocations.get(id); if (typeof invocation === 'undefined') { - yomichan.logWarning(new Error(`Request ${id} not found for ack`)); + yomichan.logWarning(new Error(`Request ${id} not found for acknowledgement`)); return; } if (invocation.ack) { - this._onError(id, new Error(`Request ${id} already ack'd`)); + this._onError(id, `Request ${id} already acknowledged`); return; } @@ -122,9 +130,9 @@ class CrossFrameAPIPort extends EventDispatcher { const responseTimeout = invocation.responseTimeout; if (responseTimeout !== null) { try { - invocation.timer = setTimeout(() => this._onError(id, new Error('Timeout (response)')), responseTimeout); + invocation.timer = setTimeout(() => this._onError(id, 'Response timeout'), responseTimeout); } catch (e) { - this._onError(id, new Error('Failed to set timeout')); + this._onError(id, 'Failed to set timeout'); } } } @@ -137,7 +145,7 @@ class CrossFrameAPIPort extends EventDispatcher { } if (!invocation.ack) { - this._onError(id, new Error(`Request ${id} not ack'd`)); + this._onError(id, `Request ${id} not acknowledged`); return; } @@ -160,6 +168,10 @@ class CrossFrameAPIPort extends EventDispatcher { const invocation = this._activeInvocations.get(id); if (typeof invocation === 'undefined') { return; } + if (typeof error === 'string') { + error = new Error(`${error} (${invocation.action})`); + } + this._activeInvocations.delete(id); if (invocation.timer !== null) { clearTimeout(invocation.timer); |