{"record":{"id":"646790a6ed15e529","repo":"jackwener/OpenCLI","slug":"unexpected-result-from-reddit-reply-json-string","errorCode":null,"errorMessage":"Unexpected result from reddit reply: ${JSON.stringify(result)}","messagePattern":"Unexpected result from reddit reply: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/reddit/reply.js","lineNumber":178,"sourceCode":"    })()`);\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 === 'reddit-error') {\n            throw new CommandExecutionError(`Reddit rejected reply: ${result.detail}`);\n        }\n        if (result?.kind === 'postcondition') {\n            throw new CommandExecutionError(result.detail);\n        }\n        if (result?.kind === 'exception') {\n            throw new CommandExecutionError(`Reply failed: ${result.detail}`);\n        }\n        if (result?.kind !== 'ok') {\n            throw new CommandExecutionError(`Unexpected result from reddit reply: ${JSON.stringify(result)}`);\n        }\n        return [{ status: 'success', message: result.detail }];\n    },\n});\n","sourceCodeStart":160,"sourceCodeEnd":183,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/reply.js#L160-L183","documentation":"A defensive fallthrough error in the reddit `reply` command: thrown when the page-evaluate result's `kind` is none of the recognized values ('ok', 'http', 'reddit-error', 'postcondition', 'exception'). The full result object is JSON-stringified into the message to aid debugging of contract drift between the injected script and the CLI. It almost always indicates a version mismatch or a malformed/unexpected result shape.","triggerScenarios":"Calling the reddit reply command when page.evaluate returns an object with an unknown or missing `kind` field — e.g. a newer/older injected script, the evaluate returning undefined/null because the script failed to return, or Reddit serving a page where the script's early return path is skipped.","commonSituations":"Mixing versions of the CLI and its browser bundle; Reddit serving an unexpected interstitial page so the script returns undefined; editing the injected script and forgetting to update the kind taxonomy.","solutions":["Inspect the JSON payload in the message to see what shape actually came back","Ensure the browser bundle/injected script and CLI code are the same version (reinstall/update the package)","Check the evaluate returned an explicit object with a `kind` field on every code path","File/patch the missing `kind` case in the injected script's result mapping"],"exampleFix":"// before\nconst result = await page.evaluate(scriptThatMayReturnUndefined);\n// after\nconst result = (await page.evaluate(scriptThatMayReturnUndefined)) || { kind: 'exception', detail: 'script returned nothing' };","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function hasKnownKind(r) {\n  return r != null && typeof r === 'object' &&\n    ['ok','http','reddit-error','postcondition','exception'].includes(r.kind);\n}","tryCatchPattern":"try {\n  await cli.run('reddit reply', { 'post-id': postId, text });\n} catch (e) {\n  if (/Unexpected result from reddit reply/.test(e.message)) {\n    const payload = JSON.parse(e.message.split(': ').slice(1).join(': '));\n    console.error('Unknown result kind:', payload); // report/patch the missing kind\n  } else throw e;\n}","preventionTips":["Keep CLI and its browser bundle versions in sync (reinstall on mismatch)","Ensure every code path in the injected script returns an object with a `kind` field","Treat undefined/null evaluate results as a defect and normalize them early"],"tags":["reddit","contract-mismatch","defensive"],"backgroundTag":"unexpected-result-shape","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}