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

Warn if unexpected key is in the toml #5689

Merged
merged 7 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
28 changes: 28 additions & 0 deletions packages/wrangler/src/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,34 @@ describe("deploy", () => {
"
`);
});

it("should warn user when additional properties are passed to a services config", async () => {
writeWranglerToml({
d1_databases: [
{
binding: "MY_DB",
database_name: "my-database",
database_id: "xxxxxxxxx",
// @ts-expect-error Depending on a users editor setup a type error in the toml will not be displayed.
// This test is checking that warnings for type errors are displayed
tail_consumers: [{ service: "<TAIL_WORKER_NAME>" }],
},
],
});
writeWorkerSource();
mockSubDomainRequest();
mockUploadWorkerRequest();

await runWrangler("deploy ./index");

expect(std.warn).toMatchInlineSnapshot(`
"▲ [WARNING] Processing wrangler.toml configuration:

- Unexpected fields found in d1_databases[0] field: \\"tail_consumers\\"

"
`);
});
});

describe("environments", () => {
Expand Down
1 change: 1 addition & 0 deletions packages/wrangler/src/config/validation-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ const isRecord = (
): value is Record<string | number | symbol, unknown> =>
typeof value === "object" && value !== null && !Array.isArray(value);


Skye-31 marked this conversation as resolved.
Show resolved Hide resolved
/**
* JavaScript `typeof` operator return values.
*/
Expand Down
102 changes: 102 additions & 0 deletions packages/wrangler/src/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1998,6 +1998,13 @@ const validateDurableObjectBinding: ValidatorFn = (
isValid = false;
}

validateAdditionalProperties(diagnostics, field, Object.keys(value), [
"class_name",
"environment",
"name",
"script_name",
]);

return isValid;
};

Expand Down Expand Up @@ -2048,6 +2055,11 @@ const validateCflogfwdrBinding: ValidatorFn = (diagnostics, field, value) => {
isValid = false;
}

validateAdditionalProperties(diagnostics, field, Object.keys(value), [
"destination",
"name",
]);

return isValid;
};

Expand All @@ -2072,6 +2084,8 @@ const validateBrowserBinding =
isValid = false;
}

validateAdditionalProperties(diagnostics, field, Object.keys(value), ["binding"]);

return isValid;
};

Expand Down Expand Up @@ -2289,6 +2303,14 @@ const validateKVBinding: ValidatorFn = (diagnostics, field, value) => {
);
isValid = false;
}


validateAdditionalProperties(diagnostics, field, Object.keys(value), [
"binding",
"id",
"preview_id",
]);

return isValid;
};

Expand Down Expand Up @@ -2336,6 +2358,13 @@ const validateSendEmailBinding: ValidatorFn = (diagnostics, field, value) => {
);
isValid = false;
}

validateAdditionalProperties(diagnostics, field, Object.keys(value), [
"allowed_destination_addresses",
"destination_address",
"name",
]);

return isValid;
};

Expand Down Expand Up @@ -2444,6 +2473,14 @@ const validateR2Binding: ValidatorFn = (diagnostics, field, value) => {
);
isValid = false;
}

validateAdditionalProperties(diagnostics, field, Object.keys(value), [
"binding",
"bucket_name",
"preview_bucket_name",
"jurisdiction",
]);

return isValid;
};

Expand All @@ -2457,6 +2494,7 @@ const validateD1Binding: ValidatorFn = (diagnostics, field, value) => {
return false;
}
let isValid = true;

// D1 databases must have a binding and either a database_name or database_id.
if (!isRequiredProperty(value, "binding", "string")) {
diagnostics.errors.push(
Expand Down Expand Up @@ -2487,6 +2525,16 @@ const validateD1Binding: ValidatorFn = (diagnostics, field, value) => {
isValid = false;
}

validateAdditionalProperties(diagnostics, field, Object.keys(value), [
"binding",
"database_id",
"database_internal_env",
"database_name",
"migrations_dir",
"migrations_table",
"preview_database_id",
]);

return isValid;
};

Expand Down Expand Up @@ -2515,6 +2563,12 @@ const validateVectorizeBinding: ValidatorFn = (diagnostics, field, value) => {
);
isValid = false;
}

validateAdditionalProperties(diagnostics, field, Object.keys(value), [
"binding",
"index_name",
]);

return isValid;
};

Expand Down Expand Up @@ -2554,6 +2608,12 @@ const validateConstellationBinding: ValidatorFn = (
"Constellation Bindings are currently in beta to allow the API to evolve before general availability.\nPlease report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose\nNote: Run this command with the environment variable NO_CONSTELLATION_WARNING=true to hide this message\n\nFor example: `export NO_CONSTELLATION_WARNING=true && wrangler <YOUR COMMAND HERE>`"
);
}

validateAdditionalProperties(diagnostics, field, Object.keys(value), [
"binding",
"project_id",
]);

return isValid;
};

Expand Down Expand Up @@ -2584,6 +2644,13 @@ const validateHyperdriveBinding: ValidatorFn = (diagnostics, field, value) => {
);
isValid = false;
}

validateAdditionalProperties(diagnostics, field, Object.keys(value), [
"binding",
"id",
"localConnectionString",
]);

return isValid;
};

Expand Down Expand Up @@ -2771,6 +2838,12 @@ const validateAnalyticsEngineBinding: ValidatorFn = (
);
isValid = false;
}

validateAdditionalProperties(diagnostics, field, Object.keys(value), [
"binding",
"dataset",
]);

return isValid;
};

Expand Down Expand Up @@ -2896,6 +2969,12 @@ const validateMTlsCertificateBinding: ValidatorFn = (
);
isValid = false;
}

validateAdditionalProperties(diagnostics, field, Object.keys(value), [
"binding",
"certificate_id",
]);

return isValid;
};

Expand Down Expand Up @@ -2956,7 +3035,14 @@ function validateQueues(envName: string): ValidatorFn {
) {
isValid = false;
}

validateAdditionalProperties(diagnostics, field, Object.keys(value), [
"binding",
"delivery_delay",
"queue",
]);
}

return isValid;
};
}
Expand Down Expand Up @@ -3018,6 +3104,22 @@ const validateConsumer: ValidatorFn = (diagnostics, field, value, _config) => {
}
}

validateAdditionalProperties(
diagnostics,
field,
Object.keys(value),
[
"dead_letter_queue",
"max_batch_size",
"max_batch_timeout",
"max_concurrency",
"max_retries",
"queue",
"retry_delay",
"type",
"visibility_timeout_ms",
]
);
return isValid;
};

Expand Down
Loading
Loading