Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions .changeset/observability-null-validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@cloudflare/workers-utils": patch
---

Return a clear error when `observability` is set to `null`

`validateObservability` guarded only against `undefined`, so a `null` value (valid in JSON/JSONC config) passed the `typeof value === "object"` check and then threw `TypeError: Cannot read properties of null (reading 'enabled')` while validating the config. It now rejects `null` with the same `"observability" should be an object but got null.` diagnostic that the sibling `cache` validator already produces.
2 changes: 1 addition & 1 deletion packages/workers-utils/src/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6184,7 +6184,7 @@ const validateObservability: ValidatorFn = (diagnostics, field, value) => {
return true;
}

if (typeof value !== "object") {
if (typeof value !== "object" || value === null) {
diagnostics.errors.push(
`"${field}" should be an object but got ${JSON.stringify(value)}.`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9828,6 +9828,22 @@ describe("normalizeAndValidateConfig()", () => {
`);
});

it("should error if observability is null", ({ expect }) => {
const { diagnostics } = normalizeAndValidateConfig(
{ observability: null } as unknown as RawConfig,
undefined,
undefined,
{ env: undefined }
);

expect(diagnostics.hasWarnings()).toBe(false);
expect(diagnostics.hasErrors()).toBe(true);
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
"Processing wrangler configuration:
- "observability" should be an object but got null."
`);
});

it("should not warn on full observability config", ({ expect }) => {
const { diagnostics } = normalizeAndValidateConfig(
{
Expand Down
Loading