{"record":{"id":"6d848f27c24f7207","repo":"jackwener/OpenCLI","slug":"label-could-not-find-location-location","errorCode":null,"errorMessage":"${label} could not find location \"${location}\".","messagePattern":"(.+?) could not find location \"(.+?)\"\\.","errorType":"error_code","errorClass":"EmptyResultError","httpStatus":404,"severity":"error","filePath":"clis/wttr/utils.js","lineNumber":28,"sourceCode":"\nexport function requireString(value, name) {\n    if (typeof value !== 'string' || !value.trim()) {\n        throw new ArgumentError(`--${name} is required`);\n    }\n    return value.trim();\n}\n\nexport async function wttrFetch(location, label) {\n    // wttr.in path-encodes the location. Spaces → %20 is fine; commas survive.\n    const url = `${WTTR_BASE}/${encodeURIComponent(location)}?format=j1`;\n    let resp;\n    try {\n        resp = await fetch(url, { headers: { 'User-Agent': UA, accept: 'application/json' } });\n    } catch (err) {\n        throw new CommandExecutionError(`${label} request failed: ${err.message}`);\n    }\n    if (resp.status === 404) {\n        throw new EmptyResultError(label, `${label} could not find location \"${location}\".`);\n    }\n    if (!resp.ok) {\n        throw new CommandExecutionError(`${label} returned HTTP ${resp.status}.`);\n    }\n    let body;\n    try {\n        body = await resp.json();\n    } catch (err) {\n        // wttr.in falls back to plain-text \"Unknown location\" for some bad inputs;\n        // promote that to EmptyResult instead of pretending we got JSON.\n        throw new EmptyResultError(label, `${label} returned non-JSON body (likely unknown location).`);\n    }\n    return body;\n}\n\n// wttr.in's \"weatherDesc\" / \"lang_en\" fields are arrays of `{ value: '...' }` objects.\n// Single-element 99% of the time but the schema is a list.\nexport function pickWeatherDesc(arr) {","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/wttr/utils.js#L10-L46","documentation":"This EmptyResultError is thrown when wttr.in answers HTTP 404 for the requested location, meaning wttr.in could not geocode the given location string to any place. It is a client-input problem (unknown location), not a service outage.","triggerScenarios":"wttrFetch receives resp.status === 404 from https://wttr.in/<location>?format=j1; any command passing an unresolvable location string hits it.","commonSituations":"Misspelled city names; passing ZIP codes or region names wttr.in cannot geocode; encoding artifacts (e.g. stray characters) in the location; using place names unique to another geocoder's index.","solutions":["Use a simpler or canonical location name ('London', airport code 'LHR', or 'lat,lon')","Verify the location resolves with curl 'https://wttr.in/<loc>?format=j1'","Catch EmptyResultError and prompt the user to correct the location"],"exampleFix":"// before\nawait query({ location: 'San Fransisco' }); // typo -> 404\n// after\nawait query({ location: 'San Francisco' }); // or '37.77,-122.42'","handlingStrategy":"fallback","validationCode":"// Verify the location geocodes before calling\nconst probe = await fetch(`https://wttr.in/${encodeURIComponent(loc)}?format=j1`);\nif (probe.status === 404) throw new Error(`Unknown location: ${loc}`);","typeGuard":null,"tryCatchPattern":"try {\n  result = await query({ location });\n} catch (err) {\n  if (err instanceof EmptyResultError) {\n    result = await query({ location: nearestKnownCity });\n  } else throw err;\n}","preventionTips":["Normalize/trim location input and strip stray characters","Accept lat,lon pairs for unambiguous geocoding","Maintain a suggestion list of known-good location formats (city, IATA code, lat,lon)","Catch EmptyResultError and re-prompt the user instead of crashing"],"tags":["http-404","geocoding","empty-result"],"backgroundTag":"http-404-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}