{"record":{"id":"584f23b0a857a639","repo":"badges/shields","slug":"unparseable-jsonl-response","errorCode":null,"errorMessage":"unparseable jsonl response","messagePattern":"unparseable jsonl response","errorType":"exception","errorClass":"InvalidResponse","httpStatus":null,"severity":"error","filePath":"core/base-service/jsonl.js","lineNumber":26,"sourceCode":" * by newlines, trims each line, filters empty lines, and parses each line\n * as JSON. Throws an `InvalidResponse` error when any line is unparseable.\n *\n * @param {string|Buffer} buffer - The raw response body.\n * @returns {Array<object>} Array of parsed JSON values, one per line.\n */\nfunction parseJsonl(buffer) {\n  const logTrace = (...args) => trace.logTrace('fetch', ...args)\n  let jsonl\n  try {\n    jsonl = buffer\n      .toString()\n      .split(/\\r?\\n/)\n      .map(line => line.trim())\n      .filter(Boolean)\n      .map(line => JSON.parse(line))\n  } catch (err) {\n    logTrace(emojic.dart, 'Response JSONL (unparseable)', buffer)\n    throw new InvalidResponse({\n      prettyMessage: 'unparseable jsonl response',\n      underlyingError: err,\n    })\n  }\n  logTrace(emojic.dart, 'Response JSONL (before validation)', jsonl, {\n    deep: true,\n  })\n  return jsonl\n}\n\nexport { parseJsonl }\n","sourceCodeStart":8,"sourceCodeEnd":38,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/core/base-service/jsonl.js#L8-L38","documentation":"parseJsonl parses newline-delimited JSON responses by splitting the buffer on line breaks and JSON.parsing each line. If any line fails to parse, Shields throws InvalidResponse with prettyMessage 'unparseable jsonl response'. This indicates the upstream provider's JSONL feed was malformed or not actually JSONL.","triggerScenarios":"Any line of the split, trimmed, non-empty buffer fails JSON.parse inside parseJsonl — e.g. provider returns an HTML error page, a plain-text message, or a JSON object spanning multiple lines where JSONL was expected.","commonSituations":"Upstream JSONL format change (pretty-printed multi-line JSON instead of one object per line), rate-limit HTML page, empty or partial body from a truncated response, wrong endpoint used for a JSONL feed.","solutions":["Inspect the raw buffer logged by Shields trace ('Response JSONL (unparseable)').","Confirm the endpoint returns one JSON value per line (e.g. with curl).","Check for upstream API format changes or migration announcements.","If the provider switched to a single JSON document, use the JSON-based service/base instead.","Handle auth/limits so error pages don't reach the parser."],"exampleFix":"// before (multi-line pretty JSON treated as JSONL)\n{\"a\":\n 1}\n// after — compact each object onto one line upstream, or parse differently:\nconst json = JSON.parse(buffer) // use JSON parsing, not JSONL","handlingStrategy":"validation","validationCode":"const isProbablyJsonl = text => text.trim().split(/\\r?\\n/).filter(Boolean).every(line => { try { JSON.parse(line); return true } catch { return false } })","typeGuard":null,"tryCatchPattern":"try {\n  const jsonl = parseJsonl(buffer)\n} catch (err) {\n  console.error('bad JSONL line:', String(buffer).split('\\n').find(l => { try { JSON.parse(l); return false } catch { return true } }))\n  return fallbackBadge\n}","preventionTips":["Verify the endpoint emits one compact JSON value per line.","Guard against HTML/plain-text error pages reaching the parser.","Track upstream format-migration announcements.","Do not use the JSONL parser on endpoints that return a single JSON document."],"tags":["jsonl","parsing","upstream"],"backgroundTag":"unparseable-jsonl-response","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}