jackwener/OpenCLI · error · EmptyResultError

wttr.in returned no forecast for "${location}".

Error message

wttr.in returned no forecast for "${location}".

What it means

This EmptyResultError is thrown when wttr.in responds successfully but its j1 JSON payload contains no `weather` array (or an empty one) for the requested location. It signals a successful HTTP exchange that yielded no forecast data rather than a network or HTTP failure.

Source

Thrown at clis/wttr/forecast.js:46

            help: 'Max forecast days (1-3, wttr.in caps the response at 3 days)',
        },
    ],
    columns: [
        'rank', 'date', 'minTempC', 'maxTempC', 'avgTempC',
        'minTempF', 'maxTempF', 'avgTempF',
        'sunHour', 'totalSnowCm', 'uvIndex',
        'description', 'sunrise', 'sunset',
    ],
    func: async (args) => {
        const location = requireString(args.location, 'location');
        const days = Number(args.days ?? 3);
        if (!Number.isInteger(days) || days < 1 || days > 3) {
            throw new ArgumentError('--days must be an integer between 1 and 3 (wttr.in caps the free-tier forecast at 3 days)');
        }
        const body = await wttrFetch(location, 'wttr forecast');
        const list = Array.isArray(body?.weather) ? body.weather : [];
        if (!list.length) {
            throw new EmptyResultError('wttr forecast', `wttr.in returned no forecast for "${location}".`);
        }
        return list.slice(0, days).map((day, i) => {
            // wttr.in's day-summary uses the noon hourly slot for "main" description.
            // Index 4 = 12:00 in their 3-hour-step hourly array.
            const noon = Array.isArray(day.hourly) && day.hourly[4] ? day.hourly[4] : day.hourly?.[0] ?? {};
            const astro = Array.isArray(day.astronomy) ? day.astronomy[0] : null;
            return {
                rank: i + 1,
                date: day.date ?? null,
                minTempC: day.mintempC != null ? Number(day.mintempC) : null,
                maxTempC: day.maxtempC != null ? Number(day.maxtempC) : null,
                avgTempC: day.avgtempC != null ? Number(day.avgtempC) : null,
                minTempF: day.mintempF != null ? Number(day.mintempF) : null,
                maxTempF: day.maxtempF != null ? Number(day.maxtempF) : null,
                avgTempF: day.avgtempF != null ? Number(day.avgtempF) : null,
                sunHour: day.sunHour != null ? Number(day.sunHour) : null,
                totalSnowCm: day.totalSnow_cm != null ? Number(day.totalSnow_cm) : null,
                uvIndex: day.uvIndex != null ? Number(day.uvIndex) : null,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry with a more canonical location string (e.g. 'Paris' or '48.85,2.35')
  2. Check wttr.in availability/rate limiting with curl 'https://wttr.in/Paris?format=j1'
  3. Handle EmptyResultError in your caller and surface a friendly message

Example fix

// before
await forecast({ location: 'Nowhereville XYZ' });
// after
await forecast({ location: 'Paris' }); // or lat,lon pair
Defensive patterns

Strategy: try-catch

Validate before calling

const body = await wttrFetch(location, 'wttr forecast');
if (!Array.isArray(body?.weather) || body.weather.length === 0) {
  throw new Error(`no forecast data for ${location}`);
}

Type guard

function hasForecast(body) {
  return typeof body === 'object' && body !== null &&
    Array.isArray(body.weather) && body.weather.length > 0;
}

Try / catch

try {
  result = await forecast({ location });
} catch (err) {
  if (err instanceof EmptyResultError) {
    console.warn(`No forecast for "${location}"; try a nearby major city.`);
  } else throw err;
}

Prevention

When it happens

Trigger: wttrFetch returns a body where body.weather is missing, not an array, or []; the command then throws EmptyResultError('wttr forecast', ...).

Common situations: wttr.in returning a degenerate 200 response for obscure locations; API schema changes; rate-limited or cached empty responses; typos in location that still geocode to nothing.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/f419ff70e673a68f. Report an issue: GitHub.