Skip to content

Commit

Permalink
fix: add better error for user binding called ASSETS in pages projects (
Browse files Browse the repository at this point in the history
#7141)

* add better error for user binding called ASSETS in pages projects

* changeset + casing

* remove case insensitivity
  • Loading branch information
emily-shen authored Oct 31, 2024
1 parent 2222578 commit d938bb3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-cobras-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: throw a better error if there is an "ASSETS" user binding in a Pages projects
42 changes: 42 additions & 0 deletions packages/wrangler/src/__tests__/configuration.pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,5 +767,47 @@ describe("normalizeAndValidateConfig()", () => {
);
});
});

it("should error if there is a user binding named ASSETS at the top-level", () => {
const { diagnostics } = normalizeAndValidateConfig(
{
...pagesRawConfig,
kv_namespaces: [
{
binding: "ASSETS",
id: "1234",
},
],
},
undefined,
{ env: undefined }
);

expect(diagnostics.errors).toEqual([
"The name 'ASSETS' is reserved in Pages projects. Please use a different name for your KV Namespaces binding.",
]);
});

it("should error if there is a user binding named ASSETS in a named environment", () => {
const { diagnostics } = normalizeAndValidateConfig(
{
...pagesRawConfig,
env: {
preview: {
...pagesRawConfig.env?.preview,
vars: { ASSETS: "test_value" },
},
},
},
undefined,
{
env: "preview",
}
);

expect(diagnostics.errors).toEqual([
"The name 'ASSETS' is reserved in Pages projects. Please use a different name for your Vars binding.",
]);
});
});
});
6 changes: 6 additions & 0 deletions packages/wrangler/src/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2773,6 +2773,12 @@ const validateBindingsHaveUniqueNames = (
bindingsGroupedByName[bindingName] = [];
}

if (bindingName === "ASSETS" && isPagesConfig(config)) {
diagnostics.errors.push(
`The name 'ASSETS' is reserved in Pages projects. Please use a different name for your ${bindingType} binding.`
);
}

bindingsGroupedByName[bindingName].push(bindingType);
}
}
Expand Down

0 comments on commit d938bb3

Please sign in to comment.