{"record":{"id":"1d33f448d0581cbe","repo":"jackwener/OpenCLI","slug":"weread-official-command","errorCode":null,"errorMessage":"weread-official ${command}","messagePattern":"weread-official (.+?)","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"warning","filePath":"clis/weread-official/utils.js","lineNumber":292,"sourceCode":"    if (max !== undefined && n > max) {\n        throw new ArgumentError(`weread-official: ${label} must be <= ${max}`);\n    }\n    return n;\n}\n\nexport function requireChoice(value, choices, label, defaultValue) {\n    const text = String(value ?? defaultValue ?? '').trim();\n    if (!choices.includes(text)) {\n        throw new ArgumentError(`weread-official: ${label} must be one of: ${choices.join(', ')}`);\n    }\n    return text;\n}\n\n// ── Empty-result helper ────────────────────────────────────────────────────\n\n/** Throw EmptyResultError with a stable command label. */\nexport function emptyResult(command, hint) {\n    throw new EmptyResultError(`weread-official ${command}`, hint);\n}\n","sourceCodeStart":274,"sourceCodeEnd":294,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weread-official/utils.js#L274-L294","documentation":"emptyResult throws an EmptyResultError whose message is the stable command label 'weread-official ${command}'. Commands like runRecommend, runSimilar, listNotebooks and listBookNotes call it when the WeRead API succeeds but returns no usable data, so callers can catch an expected 'no results' condition rather than crashing on undefined data.","triggerScenarios":"Calling runRecommend/runSimilar with items the account has no recommendations for, or listNotebooks/listBookNotes when the account genuinely has zero notebooks/notes — the empty payload triggers this thrown sentinel.","commonSituations":"New WeRead accounts with no reading history or highlights; filtering criteria that exclude everything; accounts where cloud notes were deleted; testing against a fresh login.","solutions":["Catch EmptyResultError and treat it as an empty success (print a friendly 'no results' message, output [] or {}).","Verify with another WeRead client that the account actually has notebooks/notes/recommendations.","Loosen filters or options (e.g. remove restrictive mode/count choices) that may be excluding all results.","If data should exist, re-authenticate / refresh cookies — sometimes stale sessions return degraded empty payloads."],"exampleFix":"// before\nconst notes = await runBookNotes(bookId);\nrender(notes.items); // crashes on empty\n// after\ntry {\n  const notes = await runBookNotes(bookId);\n  render(notes.items);\n} catch (e) {\n  if (e instanceof EmptyResultError) render([]);\n  else throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"import { EmptyResultError } from './errors.js';\ntry {\n  const res = await runRecommend(opts);\n  render(res);\n} catch (e) {\n  if (e instanceof EmptyResultError) {\n    console.log('No results for this account/filter — treating as empty.');\n    render([]);\n  } else throw e;\n}","preventionTips":["Always wrap list/recommend commands in a catch for EmptyResultError — empty accounts are normal.","Distinguish 'no data' from 'failure' in exit codes and output so pipelines don't break.","Pre-check the account has data via another command when a non-empty result is mandatory."],"tags":["empty-result","cli","expected-condition"],"backgroundTag":"empty-result-set","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}