Errors
Errors
Section titled “Errors”Al-Falak uses a dedicated error hierarchy for all failures. All errors inherit from AlFalakError.
Error hierarchy
Section titled “Error hierarchy”AlFalakError (base)├── AstronomicalError # Sun position undefined (polar day/night)├── ConfigurationError # Invalid setup (method, madhab, etc.)└── ValidationError # Out-of-range input (coordinates, angles)Catching errors
Section titled “Catching errors”from alfalak import PrayerTimes, CalculationMethod, AlFalakError
try: pt = PrayerTimes((35.7750, -78.6336), datetime.now(), CalculationMethod.NORTH_AMERICA)except AlFalakError as e: print(f"Calculation failed: {e}")Specific error types
Section titled “Specific error types”AstronomicalError
Section titled “AstronomicalError”Raised when the sun never rises or sets (polar day/night) and PolarCircleRule.NONE is set:
from alfalak import AstronomicalError, PolarCircleRule, CalculationParameters
params = CalculationParameters(polar_circle_rule=PolarCircleRule.NONE)try: PrayerTimes((78.2232, 15.6267), datetime.now(), calculation_parameters=params)except AstronomicalError as e: print(f"Polar day/night: {e}")Also raised by crescent_geometry_at_sunset when the Sun does not set on
that date (polar day/night), since there is no sunset to evaluate the
crescent at.
ConfigurationError
Section titled “ConfigurationError”Raised for invalid configuration:
from alfalak import ConfigurationError, CalculationParameters
try: # Both method and parameters is invalid params = CalculationParameters(method=None, fajr_angle=18) # ... but passing both to PrayerTimes raisesexcept ConfigurationError as e: print(f"Invalid config: {e}")ValidationError
Section titled “ValidationError”Raised for out-of-range input:
from alfalak import ValidationError, Coordinates
try: Coordinates(latitude=91, longitude=0)except ValidationError as e: print(f"Invalid coordinates: {e}")Moon-sighting inputs follow the same rule: crescent_geometry_at_sunset
rejects a non-date day (a datetime is accepted and its calendar date
is used), a non-Coordinates location, or a non-finite
delta_t_override, as do the delta_t, yallop_*, odeh_*, and
is_*mabims* helpers for non-real, non-finite, or float-overflowing
arguments (e.g. huge ints that do not fit in a float also raise
ValidationError, never bare OverflowError; odeh_v and
yallop_q additionally reject a negative crescent width).
Hijri converter errors
Section titled “Hijri converter errors”from datetime import datefrom alfalak import ValidationError, get_calendar
try: get_calendar("mabims", country="MY").from_gregorian(date(2020, 1, 1))except ValidationError as e: print(f"Before support floor: {e}")ValidationError— support floors and bad inputs. Observational calendars resolve month starts by walking forward from a verified anchor; inputs mapping before the floor raiseValidationError(deferred) instead of returning a wrong date: Umm al-Qura supports Gregorian 2002-03-15 (1 Muharram 1423H) onward, MABIMS supports 1 Muharram 1445H (2023-07-19) onward, tabular rejects dates before 1 Muharram 1 AH (622-07-19 proleptic). Also raised for out-of-rangeHijriDatefields,adjustment_daysoutside [-2, 2], bad year/month inmonth_length,datetimepassed tofrom_gregorian(passd.date()or usegregorian_to_hijri), and days exceeding the rule’s month length.ConfigurationError— factory and bridge misuse.get_calendarraises it for unknown keys,countrywithout (or missing with)"mabims", andadjustment_daysoutside"tabular";MabimsCalendarfor unknown country codes;gregorian_to_hijriforchange_at_sunset=Truewithoutcoordinatesor anoffsetsobject without anapply(hijri, calendar)method;OffsetStorefor bad keys (not"YYYY-MM"), shifts outside {-2, -1, 1, 2} (zero included), non-dict payloads, and unreadable/unparseable JSON files. ThehijriCLI surfaces the same gates (see CLI Usage).AstronomicalError— undecidable months and polar sunset. Raised when a month start falls outside the ±4-day window around the tabular seed (search exhausted — loud failure, never a silently extended window), when Moon geometry at Makkah is unevaluable (NaNlag or failed conjunction search), and when the bridge’s Maghrib lookup hits polar day/night (propagates unwrapped, no fallback).
Error messages
Section titled “Error messages”All errors include descriptive messages:
AstronomicalError: Unable to compute prayer times: sunrise, sunset, or solar transit is undefined for these coordinates and date (polar day/night). coordinates=Coordinates(latitude=78.2232, longitude=15.6267), date=DateComponents(year=2026, month=6, day=21).See also
Section titled “See also”- Hijri Converter — calendar rules and floors behind these errors
- Moon Sighting — crescent geometry error cases
- Polar Regions — handling polar day/night
- API Reference — full API documentation