{"record":{"id":"3e7741cf1746823b","repo":"jackwener/OpenCLI","slug":"whoami-failed-result-detail","errorCode":null,"errorMessage":"whoami failed: ${result.detail}","messagePattern":"whoami failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/reddit/whoami.js","lineNumber":52,"sourceCode":"        const d = await res.json();\n        const me = d?.data;\n        if (!me?.name) {\n          return { kind: 'auth', detail: 'Not logged in to reddit.com (no identity in /api/me.json)' };\n        }\n        return { kind: 'ok', identity: me };\n      } catch (e) {\n        return { kind: 'exception', detail: String(e && e.message || e) };\n      }\n    })()`);\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 === 'exception') {\n            throw new CommandExecutionError(`whoami failed: ${result.detail}`);\n        }\n        if (result?.kind !== 'ok') {\n            throw new CommandExecutionError(`Unexpected result from reddit whoami: ${JSON.stringify(result)}`);\n        }\n\n        const u = result.identity;\n        const created = u.created_utc\n            ? new Date(u.created_utc * 1000).toISOString().split('T')[0]\n            : null;\n        const linkKarma = typeof u.link_karma === 'number' ? u.link_karma : null;\n        const commentKarma = typeof u.comment_karma === 'number' ? u.comment_karma : null;\n        const totalKarma = typeof u.total_karma === 'number'\n            ? u.total_karma\n            : (linkKarma != null && commentKarma != null ? linkKarma + commentKarma : null);\n        const inboxCount = typeof u.inbox_count === 'number' ? u.inbox_count : null;\n\n        return [\n            { field: 'Username', value: 'u/' + u.name },","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/whoami.js#L34-L70","documentation":"This CommandExecutionError is thrown when the reddit whoami script's result has kind === 'exception', meaning the in-page/in-process whoami evaluation itself threw an exception; result.detail carries the underlying error message. The CLI re-raises it as 'whoami failed: <detail>' so the original failure detail is preserved in the command error. It indicates a client-side execution failure of the whoami routine, not an HTTP status problem or missing auth.","triggerScenarios":"Calling the reddit whoami command when the embedded evaluation throws: e.g., DOM/page context unavailable, a script error inside the whoami snippet, or an unexpected runtime exception captured by the wrapper and returned as { kind: 'exception', detail }.","commonSituations":"Browser/page crashed or navigated mid-eval so the script context is gone; site markup changes causing the extraction script to throw a TypeError (reading property of undefined); automation driver version mismatch causing evaluate() to fail; timeouts propagating as exceptions inside the probe.","solutions":["Inspect result.detail (the text after 'whoami failed:') to find the original exception and fix its root cause.","Re-run the command once; transient page/context crashes often resolve on a fresh attempt.","If detail shows a script/TypeError, check whether reddit.com markup changed and update the whoami extraction script.","Update the CLI/automation stack (browser, driver, this library) to versions compatible with the current Reddit DOM.","Catch CommandExecutionError and log the full detail before deciding whether to retry or re-authenticate."],"exampleFix":"// before: treating all failures as auth and retrying login\ntry { await whoami(); } catch { await login(); }\n\n// after: branch on the failure detail\ntry {\n  await whoami();\n} catch (e) {\n  if (e instanceof AuthRequiredError) await login();\n  else throw e; // 'whoami failed: ...' is not fixable by re-login\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isWhoamiExceptionError(e) {\n  return e instanceof CommandExecutionError && e.message.startsWith('whoami failed: ');\n}","tryCatchPattern":"try {\n  await whoami();\n} catch (e) {\n  if (isWhoamiExceptionError(e)) {\n    console.error('whoami runtime failure:', e.message.slice('whoami failed: '.length));\n    // one retry after fresh page/context, then give up\n  } else throw e;\n}","preventionTips":["Keep the automation browser/page alive for the duration of the command.","Keep the CLI and embedded scripts version-aligned so the extraction logic matches current site markup.","Log result.detail immediately — it contains the original exception text.","Retry once on a fresh page before escalating; many failures are transient context crashes."],"tags":["runtime-exception","reddit","cli","script-error"],"backgroundTag":"client-script-exception","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}