Skip to content

The agent that grows with you

fix(webapp): keep the 16 MiB limit in the warning for a long-named file

unsupportedpastelsef1e337f3b14
diff --git a/apps/desktop/src/lib/browser-uploads.test.ts b/apps/desktop/src/lib/browser-uploads.test.ts
index 5a676ef3715..2797ac12d00 100644
--- a/apps/desktop/src/lib/browser-uploads.test.ts
+++ b/apps/desktop/src/lib/browser-uploads.test.ts
@@ -64,7 +64,7 @@ describe('browser file stage size', () => {
// A picked or dropped file over the upload limit gets the server's 413 "Upload request is too large",
// which doesn't say what the limit is, and a refused image pick used to show nothing at all.
const tooLarge = (name: string, type: string) => new File([new Uint8Array(BROWSER_UPLOAD_MAX_BYTES + 1)], name, { type })
- const limitMessage = (name: string) => `${name} is larger than 16 MiB, the largest file the browser can attach.`
+ const limitMessage = 'The file is larger than 16 MiB, the largest file the browser can attach.'
async function installBrowser() {
seedWebappSession('served-token')
@@ -105,7 +105,7 @@ describe('browser file stage size', () => {
})
expect(uploads()).toHaveLength(0)
- expect($notifications.get()).toContainEqual(expect.objectContaining({ kind: 'error', message: limitMessage('huge.png') }))
+ expect($notifications.get()).toContainEqual(expect.objectContaining({ kind: 'error', message: limitMessage }))
})
it('names the limit when a dropped file over it cannot be attached', async () => {
@@ -120,7 +120,23 @@ describe('browser file stage size', () => {
expect(attached).toBe(false)
expect(uploads()).toHaveLength(0)
expect($notifications.get()).toContainEqual(
- expect.objectContaining({ kind: 'warning', message: `Could not attach huge.zip: ${limitMessage('huge.zip')}` })
+ expect.objectContaining({ kind: 'warning', message: `Could not attach huge.zip: ${limitMessage}` })
)
})
+
+ // The reason is the same for any name: a long one used to push it past readableError's length cap.
+ it('still names the limit when the dropped file has a long name', async () => {
+ await installBrowser()
+ const { result } = renderComposer()
+ const name = `${'a'.repeat(150)}.zip`
+
+ await act(async () => {
+ await result.current.attachDroppedItems([{ file: tooLarge(name, 'application/zip'), path: '' }])
+ })
+
+ const warning = $notifications.get().find(notice => notice.kind === 'warning')
+
+ expect(warning?.message).toMatch(/^Could not attach a+/)
+ expect(warning?.message).toContain(limitMessage)
+ })
})
diff --git a/apps/desktop/src/lib/browser-uploads.ts b/apps/desktop/src/lib/browser-uploads.ts
index 0e5b8fccb0d..bc6fe238bd8 100644
--- a/apps/desktop/src/lib/browser-uploads.ts
+++ b/apps/desktop/src/lib/browser-uploads.ts
@@ -95,9 +95,11 @@ async function stageBrowserFile(
onStaged: OnStaged
): Promise<string> {
// The server refuses a larger file anyway, with a 413 that doesn't name the limit: say it here.
+ // The reason leaves out the name, which a drop warning adds: a long name would push the reason
+ // past readableError's length cap and lose the limit.
if (file.size > BROWSER_UPLOAD_MAX_BYTES) {
throw new Error(
- `${file.name || 'The file'} is larger than ${BROWSER_UPLOAD_MAX_BYTES / (1024 * 1024)} MiB, the largest file the browser can attach.`
+ `The file is larger than ${BROWSER_UPLOAD_MAX_BYTES / (1024 * 1024)} MiB, the largest file the browser can attach.`
)
}