Skip to content

Commit 705622c

Browse files
G4brymclaude
andcommitted
Fix crash in receiveEmail when no R2 bucket binding is found
If no R2 bucket is configured via emailRouting.targetBucket and no bucket binding exists in the environment, the email handler would crash with a TypeError when calling bucket.put() on undefined. This adds a guard that throws a descriptive error message instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 811c439 commit 705622c

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"r2-explorer": patch
3+
---
4+
5+
Add missing null check for R2 bucket in email handler to prevent crash when no bucket binding is found

packages/worker/src/modules/emails/receiveEmail.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ export async function receiveEmail(
4646
}
4747
}
4848

49+
if (!bucket) {
50+
throw new Error(
51+
"No R2 bucket binding found for email routing. Configure emailRouting.targetBucket or add an R2 bucket binding.",
52+
);
53+
}
54+
4955
const rawEmail = await streamToArrayBuffer(event.raw, event.rawSize);
5056
const parser = new PostalMime();
5157
const parsedEmail = await parser.parse(rawEmail);

0 commit comments

Comments
 (0)