Skip to content

Bug: fetch.py swallows ALL exceptions silently — impossible to debug OSM fetch failures #159

Description

@ardjo-s

Bug: fetch.py swallows ALL exceptions silently — impossible to debug OSM fetch failures

Describe the bug

fetch.py has two bare except Exception as e: blocks that catch and discard every error. When Overpass returns a 429, a timeout, a malformed JSON, or a partial payload, the error is completely swallowed. The user sees Fetching geodataframes took 120s followed by a downstream KeyError with no indication that the actual problem was an Overpass rate-limit.

To reproduce

import prettymaps
prettymaps.plot("Zurich, Switzerland", radius=1800)
# → Fetching geodataframes took 128.19 seconds
# → KeyError: 'highway'   ← no indication that Overpass returned empty/partial data

Expected behavior

Errors during OSM data fetching should be logged or surfaced so the user can understand why a render failed and take action (retry, use a different Overpass endpoint, reduce radius, etc.).

Root cause

Line 609unified_osm_request main fetch:

try:
    all_features = ox.features.features_from_polygon(bbox, tags=combined_tags)
except Exception as e:
    all_features = GeoDataFrame(geometry=[])   # silently empty, no log

Line 692 — per-layer split:

except Exception as e:
    # print(f"Error fetching {layer}: {e}")    ← commented out!
    gdfs[layer] = GeoDataFrame(geometry=[])

Suggested fix

  1. Uncomment the print/log line, or use the logging module:
except Exception as e:
    logging.warning(f"Error fetching layer '{layer}': {e}")
  1. Distinguish recoverable errors (empty result) from fatal ones (auth, network):
except (ConnectionError, TimeoutError) as e:
    raise RuntimeError(f"Overpass API unreachable: {e}") from e
except Exception as e:
    logging.warning(f"Layer '{layer}' fetch failed: {e}")
  1. Surface Overpass 429 responses with a retry hint and User-Agent header guidance.

Environment

  • prettymaps v1.4.2
  • Python 3.10.18 (Homebrew)
  • osmnx 1.2.2
  • macOS 15, ARM64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions