{"record":{"id":"d88c17c1d2c02bd0","repo":"jackwener/OpenCLI","slug":"reddit-com-result-error","errorCode":null,"errorMessage":"reddit.com: ${result.error}","messagePattern":"reddit\\.com: (.+?)","errorType":"error_code","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/reddit/saved.js","lineNumber":45,"sourceCode":"        const limit = ${kwargs.limit};\n        const res = await fetch('/user/' + username + '/saved.json?limit=' + limit + '&raw_json=1', {\n          credentials: 'include'\n        });\n        const d = await res.json();\n        return (d?.data?.children || []).map(c => ({\n          title: c.data.title || c.data.body?.slice(0, 100) || '',\n          subreddit: c.data.subreddit_name_prefixed || 'r/' + (c.data.subreddit || '?'),\n          score: c.data.score || 0,\n          comments: c.data.num_comments || 0,\n          url: 'https://www.reddit.com' + (c.data.permalink || ''),\n        }));\n      } catch (e) {\n        return { error: e.toString() };\n      }\n    })()`);\n        if (result?.error) {\n            if (String(result.error).includes('Not logged in'))\n                throw new AuthRequiredError('reddit.com', result.error);\n            throw new CommandExecutionError(result.error);\n        }\n        return (result || []).slice(0, kwargs.limit);\n    }\n});\n","sourceCodeStart":27,"sourceCodeEnd":51,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/saved.js#L27-L51","documentation":"Thrown by the reddit `saved` command when the in-page script returns a result with an `error` field that is NOT the 'Not logged in' case. The error is forwarded as `reddit.com: <error>` under CommandExecutionError (auth failures get the dedicated AuthRequiredError instead). It represents any other failure inside the page-context fetch/scrape of saved posts.","triggerScenarios":"The page.evaluate script catches an exception and returns { error: e.toString() }, and the string does not contain 'Not logged in' — e.g. fetch failures inside reddit.com, unexpected JSON shapes, or DOM/API changes breaking the scrape.","commonSituations":"Reddit changing the saved-posts API or markup; rate limiting causing in-page fetches to fail; the saved list being huge and a chunked request failing; CORS/credentials anomalies after a session refresh.","solutions":["Read the `result.error` text after the 'reddit.com:' prefix for the root cause","Confirm the session is still valid — an expired session can surface as a non-auth-looking error; re-login and retry","Update the CLI if Reddit changed its saved-posts endpoints/markup","Retry after a delay if the error indicates a transient fetch failure","Catch CommandExecutionError and degrade gracefully (show partial/empty saved list with a warning)"],"exampleFix":"// before\nconst saved = await runCli(['reddit', 'saved']);\n// after\nlet saved;\ntry { saved = await runCli(['reddit', 'saved']); }\ncatch (e) { if (e.message.startsWith('reddit.com:')) { await loginReddit(); saved = await runCli(['reddit', 'saved']); } else throw e; }","handlingStrategy":"try-catch","validationCode":"// Pre-check login state cheaply inside the session:\nconst me = await page.evaluate(\"fetch('/api/me.json?raw_json=1',{credentials:'include'}).then(r=>r.json())\");\nif (!me?.name) throw new Error('Not logged in — authenticate first');","typeGuard":"function isInPageError(r) {\n  return r != null && typeof r === 'object' && typeof r.error === 'string' && !r.error.includes('Not logged in');\n}","tryCatchPattern":"try {\n  const saved = await runCli(['reddit', 'saved']);\n} catch (e) {\n  if (e.message.startsWith('reddit.com:')) {\n    console.error('Saved-list scrape failed:', e.message.slice('reddit.com:'.length));\n    await loginReddit(); // refresh session, then retry once\n  } else throw e;\n}","preventionTips":["Refresh the session periodically — stale sessions cause odd in-page errors","Update the package when Reddit changes its saved-list endpoints","Retry with backoff for transient fetch failures inside the page"],"tags":["reddit","scraping","in-page-error"],"backgroundTag":"scrape-runtime-error","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}