Skip to content

fix(cf): make timezone_name optional - #1099

Open
PedroRosalba wants to merge 1 commit into
cloudflare:mainfrom
PedroRosalba:fix/cf-timezone-optional
Open

PedroRosalba wants to merge 1 commit into
cloudflare:mainfrom
PedroRosalba:fix/cf-timezone-optional

Conversation

@PedroRosalba

Copy link
Copy Markdown

Problem

request.cf.timezone is optional in workers-types (geolocation data can be missing for a client IP, and tooling-supplied cf objects often omit it), but worker-sys declares the getter as Result<String> and Cf::timezone_name() unwraps it. A request without a timezone panics in both --dev and --release builds.

Fix

Declare the getter as Result<Option<String>> and return Option<String> from Cf::timezone_name(), following #776 / #777 which made as_organization and asn optional the same way. The feature-gated Cf::timezone() already propagated the glue error with ?; it now returns the typed Error::TimezoneError when the field is absent.

This changes the return type of timezone_name() from String to Option<String>, the same patch-level treatment #777 received.

Tests

Adds a /cf/timezone-name route and a spec that dispatches a request with and without cf.timezone. Panics on main, passes with this change.

Tested on macOS (Apple Silicon) only.

`request.cf.timezone` is optional in workers-types (geolocation data can
be missing for a client IP, and tooling-supplied `cf` objects often omit
it), but worker-sys declared the getter as `Result<String>` and
`Cf::timezone_name()` unwrapped it, so a request without a timezone
panicked in both `--dev` and `--release` builds.

Declare the getter as `Result<Option<String>>` and return `Option<String>`
from `Cf::timezone_name()`, following cloudflare#776 / cloudflare#777 which made
`as_organization` and `asn` optional the same way. The feature-gated
`Cf::timezone()` already propagated the glue error with `?`; it now
returns the typed `Error::TimezoneError` when the field is absent.

Adds a `/cf/timezone-name` route and a test that dispatches a request
with and without `cf.timezone`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant