Sun Calculation Failed
sun_calculation_failed422
Sunrise or sunset couldn't be computed for this date and location. Verify inputs or use a different date.
What this means
A calculation that depended on sunrise or sunset time for the requested location and date couldn't produce a result. This affects sunrise-anchored calculations: panchanga (which uses sunrise as the day boundary), hora and choghadiya (slot systems anchored to sunrise/sunset), and any other operation that needs to know when the Sun crosses the local horizon. We surface this distinctly from polar_latitude_unsupported because the conditions overlap but aren't identical — you can hit sun_calculation_failed at slightly lower latitudes around the solstices.
When you'll see this
- A panchanga or muhurta request at a latitude above ~65° on a date close to the summer or winter solstice.
- A hora or choghadiya calculation in the same conditions.
- Input parameters produced an unresolvable case for sunrise (e.g. invalid timezone combined with edge-case latitude).
- A test or fixture used extreme polar conditions.
Learn more about how this works
Sunrise and sunset are computed by finding the moment the Sun's center (or limb, depending on convention) crosses the local horizon. At extreme latitudes near the solstices, this crossing doesn't happen — the Sun stays above the horizon for the whole day (polar day) or below it (polar night). When that's the case, there's no sunrise to anchor on, and operations that need sunrise simply can't proceed.
The most common gotcha: this error can fire at lower latitudes than polar_latitude_unsupported. The polar circle is at ~66.5°, but near the solstices the Sun can fail to set at latitudes as low as ~65° depending on atmospheric refraction conventions. You might hit this for a place that doesn't feel "polar" — Iceland's northern coast, for instance, on dates close to June 21.
Example response
{
"success": false,
"error": "sun_calculation_failed",
"message": "Sunrise or sunset could not be computed for this date and location. Verify latitude, longitude, and timezone, or provide a specific birth time.",
"details": [],
"retry_after": null,
"doc_url": "https://docs.asterwise.com/reference/errors/sun_calculation_failed",
"request_id": "req_01HXYZABCDEFGH",
"timestamp": "2026-05-25T12:34:56Z"
}
- Verify the date and location combination is reasonable. Most occurrences are at extreme latitudes near solstices.
- For panchanga/muhurta/hora calculations at high latitudes, choose a date closer to an equinox (March or September) where the Sun does cross the horizon.
- If the location is genuinely problematic year-round (above 70° latitude), use a nearby non-polar reference location for sunrise-based calculations.
Pre-validate or pre-detect the polar-date condition on your side, or offer a fallback location when the error fires.
Python:
Production handler
- Python
- TypeScript
import httpx
def call_sunrise_anchored(url, headers, payload, fallback_lat=None, fallback_lon=None):
response = httpx.post(url, headers=headers, json=payload, timeout=30)
if response.status_code == 422:
body = response.json()
if body.get("error") == "sun_calculation_failed" and fallback_lat is not None:
payload["lat"] = fallback_lat
payload["lon"] = fallback_lon
response = httpx.post(url, headers=headers, json=payload, timeout=30)
response.raise_for_status()
return response.json()
async function callSunriseAnchored(
url: string,
headers: HeadersInit,
payload: any,
fallback?: { lat: number; lon: number },
) {
let response = await fetch(url, {
method: "POST",
headers,
body: JSON.stringify(payload),
});
if (response.status === 422) {
const body = await response.clone().json();
if (body.error === "sun_calculation_failed" && fallback) {
payload.lat = fallback.lat;
payload.lon = fallback.lon;
response = await fetch(url, {
method: "POST",
headers,
body: JSON.stringify(payload),
});
}
}
if (!response.ok) throw new Error(`HTTP ${response.status}`);
return response.json();
}
Avoid this error by
- For panchanga, muhurta, and hora calculations targeting global users, warn if the user's location is above 60° latitude — most occurrences cluster there.
- Cache sunrise/sunset times where you can. Astronomical events are deterministic for a fixed location-date pair, so there's no reason to recompute on every request.
- For multi-location products, document the constraint clearly so users aren't surprised by edge-case failures.
- Don't conflate this error with
polar_latitude_unsupported. They overlap but trigger at different boundaries — handle both for robust polar support.