{"record":{"id":"de44d345402b8d77","repo":"jackwener/OpenCLI","slug":"label-must-be-a-non-negative-integer-de44d3","errorCode":null,"errorMessage":"${label} must be a non-negative integer","messagePattern":"(.+?) must be a non-negative integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/suno/utils.js","lineNumber":96,"sourceCode":"export function unwrapEvaluateResult(value) {\n    if (value && typeof value === 'object' && 'session' in value && 'data' in value) {\n        return value.data;\n    }\n    return value;\n}\n\nexport function requirePositiveInt(value, label) {\n    const n = Number(value);\n    if (!Number.isInteger(n) || n < 1) {\n        throw new ArgumentError(`${label} must be a positive integer`);\n    }\n    return n;\n}\n\nexport function requireNonNegativeInt(value, label) {\n    const n = Number(value);\n    if (!Number.isInteger(n) || n < 0) {\n        throw new ArgumentError(`${label} must be a non-negative integer`);\n    }\n    return n;\n}\n\nexport function clampSlider(value, label, def) {\n    if (value === undefined || value === null || value === '') return def;\n    const n = Number(value);\n    if (!Number.isFinite(n) || n < 0 || n > 1) {\n        throw new ArgumentError(`${label} must be a number between 0 and 1`);\n    }\n    return n;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// In-page helper snippets. Each is inlined into a page.evaluate() call so\n// the browser-token is generated fresh per request and the Clerk token is\n// pulled live (avoiding 60s TTL expiry on long polls).\n// ─────────────────────────────────────────────────────────────────────────────","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/suno/utils.js#L78-L114","documentation":"requireNonNegativeInt coerces its input with Number() and requires an integer >= 0, throwing ArgumentError otherwise. It validates the `--page-offset` option for Suno pagination, so zero is allowed but negatives, fractions, and non-numeric values are rejected.","triggerScenarios":"Calling a suno command with `--page-offset -1`, `--page-offset 1.5`, `--page-offset abc`, or an empty value that coerces to NaN. Any negative offset intended to mean 'last page' or 'auto' is unsupported.","commonSituations":"Trying negative offsets to page backwards; pasting fractional values; shell variable interpolating to an empty or non-numeric string (e.g. `--page-offset $PAGE` with PAGE unset).","solutions":["Use a whole number >= 0; offset 0 is the first page.","Default: omit the flag entirely when you want the first page.","Fix the shell variable so it expands to a valid non-negative integer (e.g. `PAGE=${PAGE:-0}`).","Check the label in the error message to identify the offending flag."],"exampleFix":"// before\nopencli suno list --page-offset -1\n// after\nopencli suno list --page-offset 0","handlingStrategy":"validation","validationCode":"function isNonNegativeInt(v) { const n = Number(v); return Number.isInteger(n) && n >= 0; }\nif (!isNonNegativeInt(pageOffset)) throw new Error('--page-offset must be a non-negative integer');","typeGuard":"function isNonNegativeInt(v) {\n  const n = Number(v);\n  return Number.isFinite(n) && Number.isInteger(n) && n >= 0;\n}","tryCatchPattern":"try {\n  await run({ pageOffset: requireNonNegativeInt(rawOffset, 'page-offset') });\n} catch (err) {\n  if (err.name === 'ArgumentError' && /non-negative integer/.test(err.message)) {\n    pageOffset = 0; // fall back to first page\n  } else throw err;\n}","preventionTips":["Use 0, not -1, for the first page; omit the flag when possible.","Never use negative offsets for 'backwards' paging — subtract from the current offset instead.","Default unset env/shell vars (${PAGE:-0}).","Reuse requireNonNegativeInt in wrapper scripts."],"tags":["cli","argument-validation","pagination"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}