diff --git a/.changeset/observability-null-validation.md b/.changeset/observability-null-validation.md new file mode 100644 index 0000000000..f710a22fcb --- /dev/null +++ b/.changeset/observability-null-validation.md @@ -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. diff --git a/packages/workers-utils/src/config/validation.ts b/packages/workers-utils/src/config/validation.ts index 0628dcfd84..21eeac4d39 100644 --- a/packages/workers-utils/src/config/validation.ts +++ b/packages/workers-utils/src/config/validation.ts @@ -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)}.` ); diff --git a/packages/workers-utils/tests/config/validation/normalize-and-validate-config.test.ts b/packages/workers-utils/tests/config/validation/normalize-and-validate-config.test.ts index dc94e3142a..ede79be92d 100644 --- a/packages/workers-utils/tests/config/validation/normalize-and-validate-config.test.ts +++ b/packages/workers-utils/tests/config/validation/normalize-and-validate-config.test.ts @@ -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( {