{"record":{"id":"f27a5f764d126cd2","repo":"jackwener/OpenCLI","slug":"unexpected-result-from-reddit-read-json-stringi","errorCode":null,"errorMessage":"Unexpected result from reddit read: ${JSON.stringify(result)}","messagePattern":"Unexpected result from reddit read: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/reddit/read.js","lineNumber":584,"sourceCode":"            throw new EmptyResultError(result.detail);\n        }\n        if (result.kind === 'auth') {\n            throw new AuthRequiredError('reddit.com', result.detail);\n        }\n        if (result.kind === 'http') {\n            throw new CommandExecutionError(`HTTP ${result.httpStatus} from ${result.where}`);\n        }\n        if (result.kind === 'malformed') {\n            throw new CommandExecutionError(result.detail);\n        }\n        if (result.kind === 'parser-drift') {\n            throw new CommandExecutionError(result.detail);\n        }\n        if (result.kind === 'expand-failed') {\n            throw new CommandExecutionError(result.detail);\n        }\n        if (result.kind !== 'ok' || !Array.isArray(result.rows)) {\n            throw new CommandExecutionError(`Unexpected result from reddit read: ${JSON.stringify(result)}`);\n        }\n        return result.rows;\n    },\n});\n","sourceCodeStart":566,"sourceCodeEnd":589,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/read.js#L566-L589","documentation":"Final safety check in the reddit read handler: after all known envelope kinds are handled, the result must be kind 'ok' with an array of rows. Anything else (unknown kind, ok without rows array) triggers this CommandExecutionError that stringifies the whole envelope for debugging. It means the script returned a shape the host does not understand.","triggerScenarios":"The in-page script returns a new/unknown envelope kind after a library partial update, or returns kind 'ok' but with rows missing/null due to a script bug.","commonSituations":"Version mismatch between the injected page script and the host handler after an upgrade; manual edits to the script; corrupted install.","solutions":["Read the JSON in the message to see the actual result and its kind.","Reinstall/upgrade the library so the page script and host handler versions match.","If kind is 'ok' with missing rows, report a bug — the script's success path is returning a non-array."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const isOkEnvelope = (r) => r && typeof r === 'object' && r.kind === 'ok' && Array.isArray(r.rows);","tryCatchPattern":"try {\n  return await redditRead(postId);\n} catch (e) {\n  if (e instanceof CommandExecutionError && /Unexpected result from reddit read/.test(e.message)) {\n    console.error('Envelope contract violated — reinstall/upgrade the library');\n    // Log e.message (contains full envelope JSON) for a bug report\n  }\n  throw e;\n}","preventionTips":["Keep the injected page script and host handler from the same library version (no partial upgrades).","Reinstall cleanly if you see this after an update or manual patching.","Include the stringified envelope from the message when reporting bugs."],"tags":["unexpected-state","envelope","reddit"],"backgroundTag":"unexpected-result-envelope","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}