Skip to content

Commit 0bf3de8

Browse files
committed
Move check for invalid state
1 parent ad921bf commit 0bf3de8

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/snaps-rpc-methods/src/permitted/setState.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,15 @@ async function setStateImplementation(
136136
const { origin } = request as JsonRpcRequest & { origin: string };
137137
const state = await getSnapState(origin, encrypted);
138138

139-
const newState = set(state, key, value);
140-
if (!isPlainObject(newState)) {
139+
if (key === undefined && !isPlainObject(value)) {
141140
return end(
142-
rpcErrors.invalidParams('Invalid state: Root must be an object.'),
141+
rpcErrors.invalidParams(
142+
'Invalid params: Value must be an object if key is not provided.',
143+
),
143144
);
144145
}
145146

147+
const newState = set(state, key, value);
146148
await updateSnapState(origin, newState, encrypted);
147149
response.result = null;
148150
} catch (error) {

0 commit comments

Comments
 (0)