Skip to content

Commit

Permalink
Don't throw for missing preview ids in local dev mode (#3901)
Browse files Browse the repository at this point in the history
* Don't throw for preview ids in local dev

* Add changeset

* These are used now, no underscore
  • Loading branch information
DaniFoldi committed Sep 7, 2023
1 parent 7f60db2 commit a986f19
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-badgers-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Only require preview_id and preview_bucket_name in remote dev mode
14 changes: 7 additions & 7 deletions packages/wrangler/src/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -844,14 +844,14 @@ function getBindings(
const bindings = {
kv_namespaces: [
...(configParam.kv_namespaces || []).map(
({ binding, preview_id, id: _id }) => {
// In `dev`, we make folks use a separate kv namespace called
({ binding, preview_id, id }) => {
// In remote `dev`, we make folks use a separate kv namespace called
// `preview_id` instead of `id` so that they don't
// break production data. So here we check that a `preview_id`
// has actually been configured.
// This whole block of code will be obsoleted in the future
// when we have copy-on-write for previews on edge workers.
if (!preview_id) {
if (!preview_id && !local) {
// TODO: This error has to be a _lot_ better, ideally just asking
// to create a preview namespace for the user automatically
throw new Error(
Expand All @@ -860,7 +860,7 @@ function getBindings(
}
return {
binding,
id: preview_id,
id: preview_id ?? id,
};
}
),
Expand Down Expand Up @@ -889,17 +889,17 @@ function getBindings(
],
r2_buckets: [
...(configParam.r2_buckets?.map(
({ binding, preview_bucket_name, bucket_name: _bucket_name }) => {
({ binding, preview_bucket_name, bucket_name }) => {
// same idea as kv namespace preview id,
// same copy-on-write TODO
if (!preview_bucket_name) {
if (!preview_bucket_name && !local) {
throw new Error(
`In development, you should use a separate r2 bucket than the one you'd use in production. Please create a new r2 bucket with "wrangler r2 bucket create <name>" and add its name as preview_bucket_name to the r2_buckets "${binding}" in your wrangler.toml`
);
}
return {
binding,
bucket_name: preview_bucket_name,
bucket_name: preview_bucket_name ?? bucket_name,
};
}
) || []),
Expand Down

0 comments on commit a986f19

Please sign in to comment.