{"record":{"id":"8a26abf58fda1fb7","repo":"jackwener/OpenCLI","slug":"account-must-be-an-integer-between-0-and-20","errorCode":null,"errorMessage":"account must be an integer between 0 and 20","messagePattern":"account must be an integer between 0 and 20","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/gmail/utils.js","lineNumber":43,"sourceCode":"}\n\nexport function parseLimit(raw, fallback = DEFAULT_LIMIT, max = MAX_LIMIT) {\n  const value = raw ?? fallback;\n  const limit = Number(value);\n  if (!Number.isInteger(limit) || limit <= 0) {\n    throw new ArgumentError('limit must be a positive integer');\n  }\n  if (limit > max) {\n    throw new ArgumentError(`limit must be <= ${max}`);\n  }\n  return limit;\n}\n\nexport function parseAccount(raw) {\n  const value = raw ?? 0;\n  const account = Number(value);\n  if (!Number.isInteger(account) || account < 0 || account > 20) {\n    throw new ArgumentError('account must be an integer between 0 and 20');\n  }\n  return account;\n}\n\nfunction cleanString(value) {\n  return typeof value === 'string' ? value.trim() : '';\n}\n\nfunction gmailDate(value, label) {\n  let timestamp = Number(value);\n  if (!Number.isFinite(timestamp) || timestamp <= 0) {\n    throw new CommandExecutionError(`Gmail ${label} had an invalid timestamp`);\n  }\n  if (timestamp < 10_000_000_000) timestamp *= 1000;\n  if (timestamp > 10_000_000_000_000) timestamp /= 1000;\n  const date = new Date(timestamp);\n  if (Number.isNaN(date.getTime())) {\n    throw new CommandExecutionError(`Gmail ${label} had an invalid timestamp`);","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gmail/utils.js#L25-L61","documentation":"parseAccount validates the Gmail account index, which selects the /mail/u/<index>/ profile in the browser. It must be an integer from 0 to 20 (defaulting to 0). Non-integers, negatives, or values above 20 throw ArgumentError.","triggerScenarios":"Passing --account with a float, negative number, value > 20, or a non-numeric string; passing an account index that conceptually exists in Google but exceeds the library's guard range.","commonSituations":"Users with many Google accounts guessing an index above 20; scripts interpolating an unset variable producing NaN; typos like account: '1 ' with extra characters that fail Number parsing (spaces actually parse, but 'u1' does not).","solutions":["Pass an integer account index between 0 and 20 (default 0 for the first signed-in account).","Verify the correct index by checking the /mail/u/<index>/ URL in the browser when signed in.","Omit --account to use the default (0).","Fix the calling script so it doesn't pass NaN/undefined-derived values."],"exampleFix":"// before\ncli --account 25\n// after\ncli --account 1  // second signed-in Google account (/mail/u/1/)","handlingStrategy":"validation","validationCode":"const n = Number(accountRaw ?? 0);\nif (!Number.isInteger(n) || n < 0 || n > 20) {\n  throw new Error(`account must be an integer 0-20, got ${JSON.stringify(accountRaw)}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await gmailSearch({ account });\n} catch (e) {\n  if (e instanceof ArgumentError && /account must be/.test(e.message)) {\n    return gmailSearch({ account: 0 }); // default account\n  }\n  throw e;\n}","preventionTips":["Default to account 0 unless you know the /mail/u/<index>/ index you need.","Confirm the index by checking the signed-in Gmail URL in the browser.","Validate config/script inputs that supply the account index.","Avoid hardcoding indexes above the supported 0-20 range."],"tags":["validation","arguments","gmail"],"backgroundTag":"invalid-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}