Skip to content

fix(geo): ask ipinfo.io first, because ipwho.is puts some addresses in the wrong country - #4

Merged
mryll merged 2 commits into
mryll:masterfrom
RyanBeckett:fix/ip-geolocation-provider
Sep 16, 2026
Merged

mryll merged 2 commits into
mryll:masterfrom
RyanBeckett:fix/ip-geolocation-provider

Conversation

@RyanBeckett

Copy link
Copy Markdown
Contributor

The problem

ipwho.is is not merely imprecise on some networks — it is wrong by hundreds of kilometres, and consistently so.

A Virgin Media address in Ballymena, Northern Ireland resolves to Wakefield, England: roughly 350km away, across the Irish Sea, and in the wrong country of the UK. It reproduces on every request rather than intermittently, so --location auto silently reports another country's weather with nothing to suggest anything is wrong. On a laptop that moves between networks this is easy to miss, because the number looks perfectly plausible.

Evidence

Same address, same moment:

Provider Result Error
ipwho.is (current) Wakefield, England ~350 km
ip-api.com Islington, England ~500 km
ipinfo.io Ballymena, Northern Ireland correct

The change

ipinfo.io is asked first, and ipwho.is is kept as a fallback rather than removed — a provider being unreachable then still yields a location instead of dropping auto-detection entirely.

ipinfo.io's response shape differs in two ways, hence the separate type and the small helper:

  • there is no success flag — failure is an HTTP error, or a body with no loc
  • coordinates arrive as one "lat,lon" string rather than two numbers

country is already a two-letter code, so it feeds the same build_display_name slot as ipwho.is's country_code and the display name format is unchanged.

Testing

  • cargo test — 89 pass, 0 fail
  • cargo clippy — no new warnings (the two existing ones are in waybar.rs and main.rs, untouched here)
  • cargo fmt --check — clean for api.rs
  • Verified end to end on the affected network: --location auto returned Wakefield, England, GB before and Ballymena, Northern Ireland, GB after

One gotcha worth mentioning for anyone reproducing this: the 60s response cache is keyed on the requested location, so auto hits the cache before geolocation runs. Clear ~/.cache/meteobar/ between runs or the old provider's answer is served back and it looks like nothing changed.

🤖 Generated with Claude Code

RyanBeckett and others added 2 commits September 10, 2026 12:23
…n the wrong country

ipwho.is is not merely imprecise on some networks, it is wrong by hundreds
of kilometres and consistently so. A Virgin Media address in Ballymena,
Northern Ireland resolves to Wakefield, England -- roughly 350km away,
across the Irish Sea and in the wrong country of the UK. It reproduces on
every request rather than intermittently, so auto-detection silently
reports another country's weather with no hint anything is wrong.

Checked against the same address at the same moment:

  ipwho.is    Wakefield, England       ~350km out
  ip-api.com  Islington, England       ~500km out
  ipinfo.io   Ballymena, N. Ireland    correct

ipinfo.io answers first and ipwho.is is kept as a fallback rather than
removed, so a provider being unreachable still yields a location instead
of dropping auto-detection entirely.

ipinfo.io's shape differs: there is no success flag, and coordinates come
as one "lat,lon" string rather than two numbers, hence the separate
response type and the split helper. `country` is already a two-letter
code, so it feeds the same build_display_name slot as ipwho.is's
country_code.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0135HMddrDPNMpBCpVeS8nDs
- Coordinates from `loc` must be finite and within ±90/±180; a bad pair
  is an error, so the fallback runs instead of a request with NaN.
- A non-2xx status is an error (`error_for_status`), a blank city too.
- When both providers fail the message names each one with its error.
- `ipinfo_location` is the pure half, with unit tests over real shapes
  (429, bogon, blank city, malformed loc).
@mryll
mryll merged commit 5845a52 into mryll:master Sep 16, 2026
@mryll

mryll commented Sep 16, 2026

Copy link
Copy Markdown
Owner

Merged, thanks! Released in 0.5.4.

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.

2 participants