Skip to content

Commit

Permalink
fix(Sharding): properly handle errors in fetchClientValues (#6990)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceEEC committed Nov 16, 2021
1 parent fdb09cb commit c0ba2d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/sharding/Shard.js
Expand Up @@ -247,7 +247,8 @@ class Shard extends EventEmitter {
if (message?._fetchProp !== prop) return;
child.removeListener('message', listener);
this._fetches.delete(prop);
resolve(message._result);
if (!message._error) resolve(message._result);
else reject(Util.makeError(message._error));
};
child.on('message', listener);

Expand Down
12 changes: 8 additions & 4 deletions src/sharding/ShardClientUtil.js
Expand Up @@ -175,10 +175,14 @@ class ShardClientUtil {
async _handleMessage(message) {
if (!message) return;
if (message._fetchProp) {
const props = message._fetchProp.split('.');
let value = this.client;
for (const prop of props) value = value[prop];
this._respond('fetchProp', { _fetchProp: message._fetchProp, _result: value });
try {
const props = message._fetchProp.split('.');
let value = this.client;
for (const prop of props) value = value[prop];
this._respond('fetchProp', { _fetchProp: message._fetchProp, _result: value });
} catch (err) {
this._respond('fetchProp', { _fetchProp: message._fetchProp, _error: Util.makePlainError(err) });
}
} else if (message._eval) {
try {
this._respond('eval', { _eval: message._eval, _result: await this.client._eval(message._eval) });
Expand Down

0 comments on commit c0ba2d4

Please sign in to comment.