Skip to content

Commit

Permalink
Update error messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed Feb 21, 2024
1 parent bc3dbc5 commit 636d88c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('SnapInterfaceController', () => {
MOCK_SNAP_ID,
components,
),
).rejects.toThrow('UI content is unreasonably large.');
).rejects.toThrow('A Snap UI may not be larger than 250 kB.');
});

it('throws if text content is too large', async () => {
Expand All @@ -148,7 +148,7 @@ describe('SnapInterfaceController', () => {
MOCK_SNAP_ID,
components,
),
).rejects.toThrow('UI text content is unreasonably large.');
).rejects.toThrow('The text in a Snap UI may not be larger than 50 kB.');
});
});

Expand Down Expand Up @@ -368,7 +368,7 @@ describe('SnapInterfaceController', () => {
id,
newContent,
),
).rejects.toThrow('UI content is unreasonably large.');
).rejects.toThrow('A Snap UI may not be larger than 250 kB.');
});

it('throws if text content is too large', async () => {
Expand Down Expand Up @@ -401,7 +401,7 @@ describe('SnapInterfaceController', () => {
id,
newContent,
),
).rejects.toThrow('UI text content is unreasonably large.');
).rejects.toThrow('The text in a Snap UI may not be larger than 50 kB.');
});

it('throws if the interface does not exist', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { nanoid } from 'nanoid';

import { constructState } from './utils';

const MAX_UI_CONTENT_SIZE = 256000; // 250 kb
const MAX_TEXT_LENGTH = 51200; // 50 kb
const MAX_UI_CONTENT_SIZE = 250_000; // 250 kb
const MAX_TEXT_LENGTH = 50_000; // 50 kb

const controllerName = 'SnapInterfaceController';

Expand Down Expand Up @@ -260,13 +260,18 @@ export class SnapInterfaceController extends BaseController<
async #validateContent(content: Component) {
const size = getJsonSize(content);

assert(size <= MAX_UI_CONTENT_SIZE, `A Snap UI may not be larger than ${MAX_UI_CONTENT_SIZE / 1000} kB.`);
assert(
size <= MAX_UI_CONTENT_SIZE,
`A Snap UI may not be larger than ${MAX_UI_CONTENT_SIZE / 1000} kB.`,
);

const textSize = getTotalTextLength(content);

assert(
textSize <= MAX_TEXT_LENGTH,
'UI text content is unreasonably large.',
`The text in a Snap UI may not be larger than ${
MAX_TEXT_LENGTH / 1000
} kB.`,
);

await this.#triggerPhishingListUpdate();
Expand Down

0 comments on commit 636d88c

Please sign in to comment.