{"record":{"id":"8f8ae193de7a6a9b","repo":"jackwener/OpenCLI","slug":"offset-must-be-a-non-negative-integer","errorCode":null,"errorMessage":"offset must be a non-negative integer","messagePattern":"offset must be a non-negative integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/hltv/utils.js","lineNumber":74,"sourceCode":"\nexport const VERSIONS = {\n  both: null,\n  cs2: 'CS2',\n  csgo: 'CSGO',\n};\n\nexport function normalizeLimit(value, defaultValue, maxValue, label = 'limit') {\n  const raw = value ?? defaultValue;\n  const n = Number(raw);\n  if (!Number.isInteger(n) || n <= 0) throw new ArgumentError(`${label} must be a positive integer`);\n  if (n > maxValue) throw new ArgumentError(`${label} must be <= ${maxValue}`);\n  return n;\n}\n\nexport function normalizeOffset(value, defaultValue = 0) {\n  const raw = value ?? defaultValue;\n  const n = Number(raw);\n  if (!Number.isInteger(n) || n < 0) throw new ArgumentError('offset must be a non-negative integer');\n  if (n % 100 !== 0) throw new ArgumentError('offset must be a multiple of 100');\n  return n;\n}\n\nexport function normalizeChoice(value, defaultValue, choices, label) {\n  const raw = String(value ?? defaultValue);\n  if (!Object.prototype.hasOwnProperty.call(choices, raw)) {\n    throw new ArgumentError(`${label} must be one of: ${Object.keys(choices).join(', ')}`);\n  }\n  return raw;\n}\n\nexport function parseNumber(value) {\n  const raw = String(value ?? '').replace(/\\s+/g, ' ').trim();\n  if (!raw || raw === '-' || raw.toLowerCase() === 'n/a') return null;\n  const match = raw.replace(/,/g, '').match(/-?\\d+(?:\\.\\d+)?/);\n  if (!match) return null;\n  const n = Number(match[0]);","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/hltv/utils.js#L56-L92","documentation":"normalizeOffset validates the offset paging option. It throws when the value is not an integer or is negative — this message covers the negative/non-integer case (separate from the multiple-of-100 rule). HLTV stats endpoints page in fixed 100-row blocks, so arbitrary offsets are meaningless.","triggerScenarios":"Calling a command with --offset -100 or a non-integer like 50.5; passing offset as a non-numeric string that Number() coerces to NaN.","commonSituations":"Scripts computing offsets with buggy arithmetic producing negatives; users assuming 1-based paging and passing offset 1 expecting page 2.","solutions":["Use a non-negative integer offset that is a multiple of 100 (0, 100, 200...)","Remember offset is 0-based; page N corresponds to offset (N-1)*limit only if limit is 100","Check the script logic that increments the offset between pages"],"exampleFix":"// before\n--offset -100\n// after\n--offset 0  # offsets start at 0 and increase in steps of 100","handlingStrategy":"validation","validationCode":"const n = Number(opts.offset);\nif (!Number.isInteger(n) || n < 0) throw new Error('offset must be a non-negative integer');","typeGuard":"const isOffset = (v) => Number.isInteger(Number(v)) && Number(v) >= 0;","tryCatchPattern":"try {\n  await hltv.results({ offset });\n} catch (e) {\n  if (e.name === 'ArgumentError' && e.message.includes('offset')) { offset = 0; /* retry with default */ }\n  else throw e;\n}","preventionTips":["Start offsets at 0 and increment by 100","Never compute offsets from user input without validating","Treat offset as pageCount * 100, not an arbitrary row index"],"tags":["cli","validation","paging","argument-error"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}