Skip to content

Commit b56cf5d

Browse files
committed
chore: remove scope
1 parent 53fe1cb commit b56cf5d

4 files changed

Lines changed: 26 additions & 41 deletions

File tree

packages/snap/snap.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/MetaMask/snap-solana-wallet.git"
88
},
99
"source": {
10-
"shasum": "4RjH2Fi3PLR31YtD0lKhmaWKUg15umuOdm+tEeD/DAU=",
10+
"shasum": "M/TAq4KOxYiej93YfzvH5+bpPF1bJk+sGuy/LbxGV5A=",
1111
"location": {
1212
"npm": {
1313
"filePath": "dist/bundle.js",

packages/snap/src/core/utils/errors.test.ts

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ describe('errors', () => {
1919
describe('handle', () => {
2020
it('returns the result when the function succeeds', async () => {
2121
const mockFn = jest.fn().mockResolvedValue('success');
22-
const scope = 'test-scope';
2322

24-
const result = await withCatchAndThrowSnapError(scope, mockFn);
23+
const result = await withCatchAndThrowSnapError(mockFn);
2524

2625
expect(result).toBe('success');
2726
expect(mockFn).toHaveBeenCalledTimes(1);
@@ -31,9 +30,8 @@ describe('errors', () => {
3130
it('handles and re-throws errors as SnapError', async () => {
3231
const originalError = new Error('Test error');
3332
const mockFn = jest.fn().mockRejectedValue(originalError);
34-
const scope = 'test-scope';
3533

36-
await expect(withCatchAndThrowSnapError(scope, mockFn)).rejects.toThrow(
34+
await expect(withCatchAndThrowSnapError(mockFn)).rejects.toThrow(
3735
SnapError,
3836
);
3937

@@ -44,17 +42,16 @@ describe('errors', () => {
4442
it('logs errors with the correct scope and error details', async () => {
4543
const originalError = new Error('Test error');
4644
const mockFn = jest.fn().mockRejectedValue(originalError);
47-
const scope = 'test-scope';
4845

4946
try {
50-
await withCatchAndThrowSnapError(scope, mockFn);
47+
await withCatchAndThrowSnapError(mockFn);
5148
} catch (error) {
5249
// Expected to throw
5350
}
5451

5552
expect(mockLogger.error).toHaveBeenCalledWith(
5653
{ error: expect.any(SnapError) },
57-
expect.stringContaining(`[${scope}] Error occurred:`),
54+
expect.stringContaining(`[SnapError]`),
5855
);
5956

6057
expect(mockLogger.error).toHaveBeenCalledTimes(1);
@@ -66,9 +63,8 @@ describe('errors', () => {
6663
it('handles non-Error objects and converts them to SnapError', async () => {
6764
const nonErrorValue = 'string error';
6865
const mockFn = jest.fn().mockRejectedValue(nonErrorValue);
69-
const scope = 'test-scope';
7066

71-
await expect(withCatchAndThrowSnapError(scope, mockFn)).rejects.toThrow(
67+
await expect(withCatchAndThrowSnapError(mockFn)).rejects.toThrow(
7268
SnapError,
7369
);
7470

@@ -80,9 +76,8 @@ describe('errors', () => {
8076

8177
it('handles null and undefined errors', async () => {
8278
const mockFn = jest.fn().mockRejectedValue(null);
83-
const scope = 'test-scope';
8479

85-
await expect(withCatchAndThrowSnapError(scope, mockFn)).rejects.toThrow(
80+
await expect(withCatchAndThrowSnapError(mockFn)).rejects.toThrow(
8681
SnapError,
8782
);
8883

@@ -92,11 +87,10 @@ describe('errors', () => {
9287
it('preserves the original error message in the SnapError', async () => {
9388
const originalError = new Error('Custom error message');
9489
const mockFn = jest.fn().mockRejectedValue(originalError);
95-
const scope = 'test-scope';
9690

9791
let caughtError: unknown;
9892
try {
99-
await withCatchAndThrowSnapError(scope, mockFn);
93+
await withCatchAndThrowSnapError(mockFn);
10094
} catch (error) {
10195
caughtError = error;
10296
}
@@ -117,9 +111,8 @@ describe('errors', () => {
117111

118112
for (const testCase of testCases) {
119113
const mockFn = jest.fn().mockResolvedValue(testCase.value);
120-
const scope = 'test-scope';
121114

122-
const result = await withCatchAndThrowSnapError(scope, mockFn);
115+
const result = await withCatchAndThrowSnapError(mockFn);
123116

124117
expect(result).toBe(testCase.value);
125118
expect(mockLogger.error).not.toHaveBeenCalled();
@@ -136,9 +129,8 @@ describe('errors', () => {
136129

137130
for (const errorType of errorTypes) {
138131
const mockFn = jest.fn().mockRejectedValue(errorType);
139-
const scope = 'test-scope';
140132

141-
await expect(withCatchAndThrowSnapError(scope, mockFn)).rejects.toThrow(
133+
await expect(withCatchAndThrowSnapError(mockFn)).rejects.toThrow(
142134
SnapError,
143135
);
144136
}
@@ -159,10 +151,9 @@ describe('errors', () => {
159151
const originalError = new Error('Test error');
160152
originalError.stack = 'Error: Test error\n at test.js:1:1';
161153
const mockFn = jest.fn().mockRejectedValue(originalError);
162-
const scope = 'test-scope';
163154

164155
try {
165-
await withCatchAndThrowSnapError(scope, mockFn);
156+
await withCatchAndThrowSnapError(mockFn);
166157
} catch (error) {
167158
// Expected to throw
168159
}
@@ -176,9 +167,8 @@ describe('errors', () => {
176167
it('handles functions that throw promises', async () => {
177168
const rejectedPromise = Promise.reject(new Error('Promise error'));
178169
const mockFn = jest.fn().mockImplementation(async () => rejectedPromise);
179-
const scope = 'test-scope';
180170

181-
await expect(withCatchAndThrowSnapError(scope, mockFn)).rejects.toThrow(
171+
await expect(withCatchAndThrowSnapError(mockFn)).rejects.toThrow(
182172
SnapError,
183173
);
184174

packages/snap/src/core/utils/errors.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export function isSnapRpcError(error: Error): boolean {
5151
}
5252

5353
export const withCatchAndThrowSnapError = async <ResponseT>(
54-
scope: string,
5554
fn: () => Promise<ResponseT>,
5655
): Promise<ResponseT> => {
5756
try {
@@ -63,7 +62,7 @@ export const withCatchAndThrowSnapError = async <ResponseT>(
6362

6463
logger.error(
6564
{ error },
66-
`[${scope}] Error occurred: ${JSON.stringify(error.toJSON(), null, 2)}`,
65+
`[SnapError] ${JSON.stringify(error.toJSON(), null, 2)}`,
6766
);
6867

6968
throw error;

packages/snap/src/index.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
7979
) as unknown as Error;
8080
}
8181

82-
const result = await withCatchAndThrowSnapError('onRpcRequest', async () =>
82+
const result = await withCatchAndThrowSnapError(async () =>
8383
handler({ origin, request }),
8484
);
8585

@@ -114,9 +114,8 @@ export const onKeyringRequest: OnKeyringRequestHandler = async ({
114114
(request.params as Record<string, Json>).origin = 'https://metamask.io';
115115
}
116116

117-
const result = await withCatchAndThrowSnapError(
118-
'onKeyringRequest',
119-
async () => handleKeyringRequest(keyring, request),
117+
const result = await withCatchAndThrowSnapError(async () =>
118+
handleKeyringRequest(keyring, request),
120119
);
121120

122121
return result ?? null;
@@ -158,7 +157,7 @@ export const onUserInput: OnUserInputHandler = async ({
158157
return;
159158
}
160159

161-
await withCatchAndThrowSnapError('onUserInput', async () =>
160+
await withCatchAndThrowSnapError(async () =>
162161
handler({ id, event, context, snapContext }),
163162
);
164163
};
@@ -184,7 +183,7 @@ export const onCronjob: OnCronjobHandler = async ({ request }) => {
184183
]),
185184
);
186185

187-
const result = await withCatchAndThrowSnapError('onCronjob', async () => {
186+
const result = await withCatchAndThrowSnapError(async () => {
188187
/**
189188
* Don't run cronjobs if client is locked or inactive
190189
* - We dont want to call cronjobs if the client is locked
@@ -232,40 +231,37 @@ export const onCronjob: OnCronjobHandler = async ({ request }) => {
232231
};
233232

234233
export const onAssetsLookup: OnAssetsLookupHandler = async (params) => {
235-
const result = await withCatchAndThrowSnapError('onAssetsLookup', async () =>
234+
const result = await withCatchAndThrowSnapError(async () =>
236235
onAssetsLookupHandler(params),
237236
);
238237
return result ?? null;
239238
};
240239

241240
export const onAssetsConversion: OnAssetsConversionHandler = async (params) => {
242-
const result = await withCatchAndThrowSnapError(
243-
'onAssetsConversion',
244-
async () => onAssetsConversionHandler(params),
241+
const result = await withCatchAndThrowSnapError(async () =>
242+
onAssetsConversionHandler(params),
245243
);
246244
return result ?? null;
247245
};
248246

249247
export const onProtocolRequest: OnProtocolRequestHandler = async (params) => {
250-
const result = await withCatchAndThrowSnapError(
251-
'onProtocolRequest',
252-
async () => onProtocolRequestHandler(params),
248+
const result = await withCatchAndThrowSnapError(async () =>
249+
onProtocolRequestHandler(params),
253250
);
254251
return result ?? null;
255252
};
256253

257254
export const onAssetHistoricalPrice: OnAssetHistoricalPriceHandler = async (
258255
params,
259256
) => {
260-
const result = await withCatchAndThrowSnapError(
261-
'onAssetHistoricalPrice',
262-
async () => onAssetHistoricalPriceHandler(params),
257+
const result = await withCatchAndThrowSnapError(async () =>
258+
onAssetHistoricalPriceHandler(params),
263259
);
264260
return result ?? null;
265261
};
266262

267263
export const onClientRequest: OnClientRequestHandler = async ({ request }) => {
268-
const result = await withCatchAndThrowSnapError('onClientRequest', async () =>
264+
const result = await withCatchAndThrowSnapError(async () =>
269265
clientRequestHandler.handle(request),
270266
);
271267
return result ?? null;

0 commit comments

Comments
 (0)