{"record":{"id":"cfa35e3bcf45bab9","repo":"jackwener/OpenCLI","slug":"result-error","errorCode":null,"errorMessage":"${result.error}","messagePattern":"\\$\\{result\\.error\\}","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/reddit/saved.js","lineNumber":46,"sourceCode":"        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":28,"sourceCodeEnd":51,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/reddit/saved.js#L28-L51","documentation":"This is the non-auth branch of the same check in `reddit saved`: when the in-page script returned an error and it does not include 'Not logged in', the raw error string is re-thrown as a CommandExecutionError (error 3376 prefixes it; this entry is the direct rethrow at the adjacent line). Both represent a generic in-page failure while fetching the saved list; only authentication problems are routed to AuthRequiredError.","triggerScenarios":"page.evaluate catch block returns { error: e.toString() } for anything other than login issues: TypeError from missing DOM nodes, failed fetch, JSON.parse failure on an unexpected Reddit response.","commonSituations":"Reddit A/B tests changing page structure; temporary 5xx served to the in-page fetch; script bugs after partial edits to the injected code.","solutions":["Read the thrown error string to identify the underlying in-page failure","Re-login to refresh the session, then retry the saved command","Reinstall/update the package in case your injected script is out of sync with Reddit's current page","Retry after a short backoff for transient failures"],"exampleFix":"// before\nconst saved = await runCli(['reddit', 'saved']);\n// after\ntry {\n  const saved = await runCli(['reddit', 'saved']);\n} catch (e) {\n  console.error('saved list failed:', e.message); // inspect and retry once\n}","handlingStrategy":"try-catch","validationCode":"// Validate session validity before invoking:\nconst ok = await page.evaluate(\"fetch('/api/me.json?raw_json=1',{credentials:'include'}).then(r=>r.ok)\");\nif (!ok) throw new Error('Session invalid — re-login before listing saved posts');","typeGuard":"function isInPageError(r) {\n  return r != null && typeof r === 'object' && typeof r.error === 'string';\n}","tryCatchPattern":"try {\n  const saved = await runCli(['reddit', 'saved']);\n} catch (e) {\n  if (e instanceof CommandExecutionError && !/Not logged in/.test(e.message)) {\n    console.error('In-page failure:', e.message);\n    await sleep(2000); // single retry for transient issues\n  } else throw e;\n}","preventionTips":["Log the raw error string — it is the in-page exception text","Re-login after any session refresh or long idle period","Keep the injected script current with Reddit's page structure"],"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"}