Skip to content

Commit

Permalink
Fix incorrect typing of JsonRpcEngine.handle return value, and impr…
Browse files Browse the repository at this point in the history
…ove type narrowing with type guard
  • Loading branch information
MajorLift committed Jun 24, 2024
1 parent 30a57ac commit d0d7b3c
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import type { SnapRpcHook, SnapRpcHookArgs } from '@metamask/snaps-utils';
import { SNAP_STREAM_NAMES, logError } from '@metamask/snaps-utils';
import type {
Json,
JsonRpcFailure,
JsonRpcNotification,
JsonRpcRequest,
PendingJsonRpcResponse,
} from '@metamask/utils';
import {
Duration,
Expand Down Expand Up @@ -441,10 +441,14 @@ export abstract class AbstractExecutionService<WorkerType>
}

log('Parent: Sending Command', message);
const response: PendingJsonRpcResponse<Json> =
job.rpcEngine.handle(message);

if (response.error) {
// eslint is blocking `await` usage even though `handle` returns a promise.
// eslint-disable-next-line @typescript-eslint/await-thenable
const response = await job.rpcEngine.handle(message);

if (
((res): res is JsonRpcFailure =>
'error' in res && res.error !== undefined)(response)
) {
throw new JsonRpcError(
response.error.code,
response.error.message,
Expand Down

0 comments on commit d0d7b3c

Please sign in to comment.