jackwener/OpenCLI · error · ArgumentError
--days must be an integer between 1 and 3 (wttr.in caps the
Error message
--days must be an integer between 1 and 3 (wttr.in caps the free-tier forecast at 3 days)
What it means
This ArgumentError is thrown by the wttr forecast command when the --days option is not an integer in the 1-3 range. The wttr.in free-tier API only serves a 3-day forecast payload, so requesting more than 3 days is impossible and requesting 0 or non-integer values is meaningless. The library fails fast client-side before making any network request.
Source
Thrown at clis/wttr/forecast.js:41
},
{
name: 'days',
type: 'int',
default: 3,
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,View on GitHub (pinned to 49907e53dc)
Solutions
- Pass an integer between 1 and 3, e.g. --days 3
- If you need longer ranges, use a different API (wttr.in free tier caps at 3 days)
- Default to omitting --days, which defaults to 3
Example fix
// before const days = Number(args.days ?? 3); // days=7 -> ArgumentError // after const days = Math.min(3, Math.max(1, Number.parseInt(args.days ?? 3, 10)));
Defensive patterns
Strategy: validation
Validate before calling
const days = Number(args.days ?? 3);
if (!Number.isInteger(days) || days < 1 || days > 3) {
throw new Error('--days must be an integer between 1 and 3');
} Type guard
function isValidDays(v) {
const n = Number(v ?? 3);
return Number.isInteger(n) && n >= 1 && n <= 3;
} Try / catch
try {
result = await forecast({ location, days });
} catch (err) {
if (err instanceof ArgumentError) {
console.error(`Invalid --days: ${err.message}`);
} else throw err;
} Prevention
- Clamp user input to 1-3 with Math.min/Math.max before passing
- Parse with parseInt and validate Number.isInteger
- Document the 3-day free-tier cap in your CLI help text
When it happens
Trigger: Calling the forecast command with days < 1, days > 3, or a non-integer (e.g. '2.5', 'abc', ''). Number(args.days ?? 3) coerces strings, so '--days abc' becomes NaN and '--days 10' passes the truthiness check but fails the range test.
Common situations: Users assuming wttr.in supports 7-day forecasts like other weather APIs; scripts passing an unset or misparsed env var into --days; passing a float from a config file.
Related errors
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
- --to station must not be empty
- --seat-types must contain only 12306 seat letters/digits (A-
- --from and --to must differ; both resolved to ${fromStation.
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/117e440b22e06d62.
Report an issue: GitHub.