Skip to content

Commit

Permalink
Go back to using getBindingNames
Browse files Browse the repository at this point in the history
So...a bunch of tests started failing after I rebased. Turns out,
we maybe can't trust the inputs to `validateBindingsHaveUniqueNames`
to be valid since we don't actually _throw_ until we've performed
every config validation. So that means by the time we get to
`validateBindingsHaveUniqueNames`, we might have some invalid stuff
in the `Config` and we can't really trust the types. :(

So I've just gone back to using `getBindingNames` to get the binding
names, since it does all the null & type checking necessary to get
the binding names out from a binding.
  • Loading branch information
Cass Fridkin committed Mar 23, 2022
1 parent 82b1881 commit 852ad20
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/wrangler/src/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1109,21 +1109,21 @@ const validateBindingsHaveUniqueNames = (
unsafe,
vars,
wasm_modules,
}: Config
}: Partial<Config>
): boolean => {
let hasDuplicates = false;

const bindingsGroupedByType = {
"Durable Object": durable_objects.bindings.map((binding) => binding.name),
"KV Namespace": kv_namespaces.map((namespace) => namespace.binding),
"R2 Bucket": r2_buckets.map((bucket) => bucket.binding),
"Text Blob": Object.keys(text_blobs || {}),
Unsafe: unsafe.bindings.map((binding) => binding.name),
"Environment Variable": Object.keys(vars),
"WASM Module": Object.keys(wasm_modules || {}),
};

const bindingsGroupedByName = Object.entries(bindingsGroupedByType).reduce(
const bindingsGroupedByType = Object.entries({
"Durable Object": getBindingNames(durable_objects),
"KV Namespace": getBindingNames(kv_namespaces),
"R2 Bucket": getBindingNames(r2_buckets),
"Text Blob": getBindingNames(text_blobs),
Unsafe: getBindingNames(unsafe),
"Environment Variable": getBindingNames(vars),
"WASM Module": getBindingNames(wasm_modules),
});

const bindingsGroupedByName = bindingsGroupedByType.reduce(
(bindings, [bindingType, bindingNames]) => {
for (const bindingName of bindingNames) {
if (!(bindingName in bindings)) {
Expand Down

0 comments on commit 852ad20

Please sign in to comment.