Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with error handling #77

Open
kslong opened this issue Oct 13, 2022 · 1 comment
Open

Problems with error handling #77

kslong opened this issue Oct 13, 2022 · 1 comment

Comments

@kslong
Copy link

kslong commented Oct 13, 2022

Several of us have been using the astral 3 release, and have run into a problem where something we have done is causing a ValueError to be raised, and then astral is unable to handle the error. The specific error arise in sun.py around line 955 in the code, in these lines

        if tot_date != date:
            if tot_date < date:
                delta = datetime.timedelta(days=1)
            else:
                delta = datetime.timedelta(days=-1)
            new_date = date + delta

            tot = time_of_transit(
                observer,
                new_date,
                90.0 + dep,
                SunDirection.SETTING,
            ).astimezone(
                tzinfo  # type: ignore
            )
            tot_date = tot.date()
            if tot_date != date:
                raise ValueError
        return tot
    except ValueError as exc:
        if exc.args[0] == "math domain error":
            raise ValueError(
                f"Sun never reaches {dep} degrees below the horizon, at this location."
            ) from exc
        else:
            raise

The if statement at the top fail,s which causes the ValueErrror to be raised.

But the problem is that exc.args is actually empty. exc.args[0]. does not exist and this causes if statement, in the line

        if exc.args[0] == "math domain error":

to break.

I am not an expert on this, but it looked like there were a number of places in the code, where something similar might happen. As a result of this, we have dropped back to using version 2.2 of astral, which does generate the original problem for us, with the same inputs. We have however not tried to understand this.

@ChiQiao
Copy link

ChiQiao commented Oct 21, 2022

Encounter the same issue. The code to reproduce the error:

import datetime
import astral

ob = astral.Observer(latitude=23.518507, longitude=74.952246, elevation=0.0)
astral.sun.sun(ob, date=datetime.date(2022, 7, 20))

sffjunkie added a commit that referenced this issue Nov 1, 2022
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

No branches or pull requests

2 participants