From fee9ec2f069f725609422531ba9fc65f0e8df2c7 Mon Sep 17 00:00:00 2001 From: Jannik Kissinger Date: Mon, 2 Dec 2024 17:03:37 +0100 Subject: [PATCH] Improved error handling issue 209 (#263) * catch not enough values to unpack ValueError * version 6.5.7 --- CHANGELOG.rst | 11 ++++++++--- pyproject.toml | 2 +- timezonefinder/timezonefinder.py | 10 ++++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b774cb6..a913f93 100755 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,17 +2,22 @@ Changelog ========= +6.5.7 (2024-12-02) +------------------ + +* improved error handling to catch ``ValueError: not enough values to unpack`` (`Issue #209 `__) + -6.5.6 (2024-11-25) +6.5.6 (2024-12-02) ------------------ -* add musllinux Wheels for Linux. Thanks to `Pxli9130 `__ +* add musllinux Wheels for Linux. Thanks to `Pxli9130 `__ 6.5.5 (2024-11-20) ------------------ -* using ``setuptools`` only as a build dependency. Thanks to `Kristian Sloth Lauszus `__ +* using ``setuptools`` only as a build dependency. Thanks to `Kristian Sloth Lauszus `__ 6.5.4 (2024-10-22) diff --git a/pyproject.toml b/pyproject.toml index 8d1c737..4385532 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "timezonefinder" -version = "6.5.6" +version = "6.5.7" description = "python package for finding the timezone of any point on earth (coordinates) offline" authors = ["jannikmi "] license = "MIT" diff --git a/timezonefinder/timezonefinder.py b/timezonefinder/timezonefinder.py index 2c7bbfb..34b44c2 100755 --- a/timezonefinder/timezonefinder.py +++ b/timezonefinder/timezonefinder.py @@ -1,10 +1,10 @@ import json +import logging from abc import ABC, abstractmethod from io import BytesIO from pathlib import Path from struct import unpack from typing import List, Optional, Tuple, Union - import numpy as np from h3.api import numpy_int as h3 @@ -488,11 +488,17 @@ def get_polygon_boundaries(self, poly_id: int) -> Tuple[int, int, int, int]: """returns the boundaries of the polygon = (lng_max, lng_min, lat_max, lat_min) converted to int32""" poly_max_values = getattr(self, POLY_MAX_VALUES) poly_max_values.seek(4 * NR_BYTES_I * poly_id) - xmax, xmin, ymax, ymin = self._fromfile( + file_result = self._fromfile( poly_max_values, dtype=DTYPE_FORMAT_SIGNED_I_NUMPY, count=4, ) + try: + xmax, xmin, ymax, ymin = file_result + except ValueError as e: + msg = f"error reading boundaries of polygon #{poly_id}, got {file_result}" + logging.error(msg) + raise ValueError(msg) from e return xmax, xmin, ymax, ymin def outside_the_boundaries_of(self, poly_id: int, x: int, y: int) -> bool: