{"record":{"id":"7a1b609f877eea5b","repo":"jackwener/OpenCLI","slug":"label-returned-json-without-result-status-code","errorCode":null,"errorMessage":"${label} returned JSON without result.status.@code","messagePattern":"(.+?) returned JSON without result\\.status\\.@code","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/dblp/utils.js","lineNumber":66,"sourceCode":"            throw new EmptyResultError(label, 'dblp returned 404 — the requested record may not exist.');\n        }\n        throw new CommandExecutionError(`${label} returned HTTP ${res.status}`, 'Inspect the response in a browser at the same URL for more context.');\n    }\n    return res;\n}\n\nexport async function dblpFetchJson(path, label) {\n    const res = await dblpFetch(`${DBLP_ORIGIN}${path}`, label, 'application/json');\n    let body;\n    try {\n        body = await res.json();\n    }\n    catch (err) {\n        throw new CommandExecutionError(`${label} returned malformed JSON: ${err?.message ?? err}`);\n    }\n    const statusCode = String(body?.result?.status?.['@code'] ?? '').trim();\n    if (!statusCode) {\n        throw new CommandExecutionError(\n            `${label} returned JSON without result.status.@code`,\n            'dblp changed its JSON envelope or returned a partial error payload; inspect the raw response in a browser.',\n        );\n    }\n    if (statusCode !== '200') {\n        const statusText = String(body?.result?.status?.text ?? '').trim();\n        throw new CommandExecutionError(\n            `${label} returned API status ${statusCode}${statusText ? ` (${statusText})` : ''}`,\n            'dblp accepted the HTTP request but reported an API-level failure. Retry later or inspect the same query in a browser.',\n        );\n    }\n    return body;\n}\n\nexport async function dblpFetchXml(path, label) {\n    const res = await dblpFetch(`${DBLP_ORIGIN}${path}`, label, 'application/xml');\n    return res.text();\n}","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/dblp/utils.js#L48-L84","documentation":"Thrown by dblpFetchJson when the parsed JSON body lacks result.status.@code — dblp's JSON envelope is missing the expected API status field. This guards against dblp changing its response schema or returning a partial/error payload that is still valid JSON.","triggerScenarios":"res.json() parses successfully but body.result.status['@code'] is undefined/empty — e.g. the endpoint returned a different JSON shape (error payload, HTML-to-JSON, or a changed API envelope).","commonSituations":"dblp API schema changes; requesting a path that returns a different JSON structure than the search API; intermediate proxies returning their own JSON error bodies with 200.","solutions":["Inspect the raw JSON in a browser at the same URL to see the actual shape","Retry later in case dblp served a partial response","Verify the request path uses the documented /search/.../api?q=...&format=json form","If dblp changed its envelope, update the parsing code to the new schema"],"exampleFix":"// before\nconst json = await dblpFetchJson(path, 'dblp search');\n// after — guard at the call site\nconst json = await dblpFetchJson(path, 'dblp search');\nif (!json?.result?.status) console.warn('Unexpected dblp envelope, raw:', JSON.stringify(json).slice(0, 200));","handlingStrategy":"type-guard","validationCode":"const body = await res.json();\nif (!body?.result?.status?.['@code']) {\n  console.warn('Unexpected dblp envelope:', JSON.stringify(body).slice(0, 200));\n}","typeGuard":"function hasDblpEnvelope(body) {\n  return !!body && typeof body === 'object'\n    && !!body.result && typeof body.result === 'object'\n    && !!body.result.status && typeof body.result.status === 'object'\n    && typeof body.result.status['@code'] === 'string';\n}","tryCatchPattern":"try {\n  const json = await dblpFetchJson(path, 'dblp search');\n} catch (err) {\n  if (/without result\\.status/.test(err.message)) {\n    // dblp envelope changed or partial payload — dump the raw body and stop\n    console.error(err.message, err.details ?? '');\n    return null;\n  }\n  throw err;\n}","preventionTips":["Validate the envelope shape before reading fields","When dblp announces API changes, re-check the envelope schema","Inspect raw responses in a browser when shapes look off","Keep a fallback parser for alternate dblp JSON shapes"],"tags":["json","schema","dblp","api"],"backgroundTag":"unexpected-response-schema","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}