{"record":{"id":"70750af00a878c90","repo":"jackwener/OpenCLI","slug":"label-returned-non-json-body-likely-unknown-lo","errorCode":null,"errorMessage":"${label} returned non-JSON body (likely unknown location).","messagePattern":"(.+?) returned non-JSON body \\(likely unknown location\\)\\.","errorType":"error_code","errorClass":"EmptyResultError","httpStatus":null,"severity":"warning","filePath":"clis/wttr/utils.js","lineNumber":39,"sourceCode":"    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) {\n    if (!Array.isArray(arr) || !arr.length) return '';\n    const first = arr[0];\n    return typeof first?.value === 'string' ? first.value.trim() : '';\n}\n","sourceCodeStart":21,"sourceCodeEnd":51,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/wttr/utils.js#L21-L51","documentation":"wttrFetch tries resp.json() on every HTTP 200 response. wttr.in sometimes returns HTTP 200 with a plain-text body (e.g. 'Unknown location') instead of the JSON j1 payload for certain bad inputs, so the JSON parse fails. The library promotes that case to an EmptyResultError rather than surfacing a confusing parse exception, because it almost always means the location string was not recognized.","triggerScenarios":"Calling wttrFetch with a location string wttr.in cannot geocode (gibberish, empty-ish, or specially malformed input) such that wttr.in replies 200 with a non-JSON plain-text body.","commonSituations":"Passing a misspelled or invented place name that isn't caught by the 404 path; passing control characters or odd encodings; wttr.in changing its fallback behavior for unknown locations from 404 to text-200.","solutions":["Verify the location string — correct spelling, use 'City,Country' format or a known airport code (e.g. 'LHR').","Try a lat,lon pair (e.g. '48.85,2.35') if the name keeps failing.","Test the same URL in a browser (https://wttr.in/<location>?format=j1) to see the raw response.","URL-encode or strip special characters from the location before passing it."],"exampleFix":"// before\nawait wttrFetch('Nowhereville XYZ', 'weather');\n// after\nawait wttrFetch('Berlin,Germany', 'weather'); // or '52.52,13.40'","handlingStrategy":"validation","validationCode":"function isPlausibleLocation(loc) {\n  return typeof loc === 'string' && loc.trim().length > 1 && !/[\\u0000-\\u001f]/.test(loc);\n}\nif (!isPlausibleLocation(userInput)) throw new Error('Provide a real city, airport code, or lat,lon');","typeGuard":"function isNonEmptyString(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  const weather = await body('--location', loc);\n} catch (err) {\n  if (/non-JSON body/.test(err.message)) {\n    console.error(`Unknown location \"${loc}\" — try 'City,Country' or a lat,lon pair`);\n  } else throw err;\n}","preventionTips":["Prefer unambiguous inputs: 'City,Country' or ISO airport codes or 'lat,lon'.","Trim and normalize user-provided location strings before calling.","Keep a known-good fallback location to smoke-test connectivity vs. bad input.","Verify unfamiliar location strings once in a browser against wttr.in."],"tags":["empty-result","bad-input","json-parse","wttr-in"],"backgroundTag":"non-json-response-unknown-location","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}