Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add better error for user binding called ASSETS in pages projects #7141

Merged
merged 3 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.toUpperCase() === "ASSETS" && isPagesConfig(config)) {
diagnostics.errors.push(
`The name 'ASSETS' is reserved in Pages projects. Please use a different name for your ${bindingType} binding.`
Copy link
Member

@edmundhung edmundhung Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Is binding name case sensitive? Might be better to show the original name user provided.

Suggested change
`The name 'ASSETS' is reserved in Pages projects. Please use a different name for your ${bindingType} binding.`
`The name '${bindingName}' is reserved in Pages projects. Please use a different name for your ${bindingType} binding.`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turns out it is case sensitive, so you totally can deploy with 'assets' (lowercase) no issues

);
}

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