Skip to content

Commit 02ed670

Browse files
perf: Simplify JSON-RPC failure validation
1 parent 36f2212 commit 02ed670

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

packages/snaps-controllers/src/services/AbstractExecutionService.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { SnapRpcHookArgs } from '@metamask/snaps-utils';
77
import { SNAP_STREAM_NAMES, logError, logWarning } from '@metamask/snaps-utils';
88
import type {
99
Json,
10+
JsonRpcError as JsonRpcErrorType,
1011
JsonRpcNotification,
1112
JsonRpcRequest,
1213
} from '@metamask/utils';
@@ -15,7 +16,6 @@ import {
1516
assertIsJsonRpcRequest,
1617
hasProperty,
1718
inMilliseconds,
18-
isJsonRpcFailure,
1919
} from '@metamask/utils';
2020
import { nanoid } from 'nanoid';
2121
import { pipeline } from 'readable-stream';
@@ -441,12 +441,10 @@ export abstract class AbstractExecutionService<WorkerType>
441441
log('Parent: Sending Command', message);
442442
const response = await job.rpcEngine.handle(message);
443443

444-
if (isJsonRpcFailure(response)) {
445-
throw new JsonRpcError(
446-
response.error.code,
447-
response.error.message,
448-
response.error.data,
449-
);
444+
// We don't need full validation of the response here because we control it.
445+
if (hasProperty(response, 'error')) {
446+
const error = response.error as JsonRpcErrorType;
447+
throw new JsonRpcError(error.code, error.message, error.data);
450448
}
451449

452450
return response.result;

0 commit comments

Comments
 (0)