{"record":{"id":"3e37a762130efbba","repo":"jackwener/OpenCLI","slug":"invalid-chess-com-username-value-usernames-ar","errorCode":null,"errorMessage":"Invalid Chess.com username \"${value}\" Usernames are 3-25 chars: a-z, 0-9, hyphen, underscore.","messagePattern":"Invalid Chess\\.com username \"(.+?)\" Usernames are 3-25 chars: a-z, 0-9, hyphen, underscore\\.","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/chess/utils.js","lineNumber":25,"sourceCode":"export const API_BASE = 'https://api.chess.com/pub';\nexport const UA = 'Mozilla/5.0 (compatible; opencli/1.0)';\n\nconst USERNAME_RE = /^[a-zA-Z0-9_-]{3,25}$/;\nconst GAME_URL_RE = /^https:\\/\\/www\\.chess\\.com\\/game\\/(live|daily)\\/(\\d+)/i;\n\nexport function isPlainObject(value) {\n    return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction isOptionalPlainObject(value) {\n    return value === undefined || value === null || isPlainObject(value);\n}\n\nexport function validateUsername(value) {\n    const s = String(value ?? '').trim().toLowerCase();\n    if (!s) throw new ArgumentError('<username> is required');\n    if (!USERNAME_RE.test(s)) {\n        throw new ArgumentError(`Invalid Chess.com username \"${value}\"`, 'Usernames are 3-25 chars: a-z, 0-9, hyphen, underscore.');\n    }\n    return s;\n}\n\nexport function parseGameUrl(value) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError('<game-url> is required');\n    const m = s.match(GAME_URL_RE);\n    if (!m) {\n        throw new ArgumentError(\n            `Invalid Chess.com game URL: \"${value}\"`,\n            'Expected https://www.chess.com/game/live/<id> or https://www.chess.com/game/daily/<id>.',\n        );\n    }\n    return { kind: m[1].toLowerCase(), id: m[2] };\n}\n\nexport async function chessApi(path, fetchImpl = fetch) {","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/chess/utils.js#L7-L43","documentation":"An ArgumentError raised when the supplied username fails the USERNAME_RE pattern ^[a-zA-Z0-9_-]{3,25}$ (3-25 chars: letters, digits, hyphen, underscore). Chess.com usernames are constrained to this shape, so the library validates locally and fails fast before hitting the network.","triggerScenarios":"Passing a username shorter than 3 chars, longer than 25 chars, or containing spaces, '@', dots, non-ASCII, or URL characters to any command that routes through validateUsername.","commonSituations":"Pasting a display name with spaces instead of the URL-style username; passing an email address; accidentally including quotes or shell-escaping artifacts; passing a full profile URL as the username.","solutions":["Use the actual Chess.com username (the lowercase handle in the profile URL), 3-25 chars of a-z/0-9/_/- only.","Trim stray quotes, whitespace, or shell escapes from the argument.","Pre-validate in the caller with the same regex before invoking the library."],"exampleFix":"// before\nawait chessStats({ username: 'Hikaru Nakamura' }); // space -> throws\n// after\nawait chessStats({ username: 'hikaru' });","handlingStrategy":"validation","validationCode":"const USERNAME_RE = /^[a-zA-Z0-9_-]{3,25}$/;\nfunction isValidUsername(v) {\n  return typeof v === 'string' && USERNAME_RE.test(v.trim());\n}","typeGuard":"function isValidUsername(v) {\n  return typeof v === 'string' && /^[a-zA-Z0-9_-]{3,25}$/.test(v.trim());\n}","tryCatchPattern":"if (!isValidUsername(username)) {\n  throw new Error('Username must be 3-25 chars: a-z, 0-9, hyphen, underscore.');\n}\ntry {\n  const rows = await chessStats({ username });\n} catch (e) {\n  if (e.name === 'ArgumentError') console.error(e.message, e.hint || '');\n  else throw e;\n}","preventionTips":["Copy the username from the profile URL rather than the display name.","Pre-validate with the same regex the library uses.","Strip quotes and shell-escaping artifacts from CLI input."],"tags":["argument-error","validation","regex","input-validation"],"backgroundTag":"input-validation-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}