{"record":{"id":"db9ea3094b123087","repo":"jackwener/OpenCLI","slug":"label-must-be-a-number-between-0-and-1","errorCode":null,"errorMessage":"${label} must be a number between 0 and 1","messagePattern":"(.+?) must be a number between 0 and 1","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/suno/utils.js","lineNumber":105,"sourceCode":"    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// ─────────────────────────────────────────────────────────────────────────────\n\nconst BROWSER_TOKEN_JS = `JSON.stringify({ token: btoa(JSON.stringify({ timestamp: Date.now() })) })`;\nconst CLERK_TOKEN_JS = `await window.Clerk.session.getToken()`;\n\n/**\n * Build the standard header set used by every studio-api-prod.suno.com call.\n *\n * deviceId is read once per command and embedded literally; browser-token\n * and Authorization are computed inline (timestamp/JWT refresh per call).","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/suno/utils.js#L87-L123","documentation":"clampSlider validates numeric slider-style options (weirdness, styleWeight) that Suno expects in the [0,1] range. Non-finite values (NaN/Infinity) or numbers outside 0–1 raise ArgumentError instead of being silently clamped.","triggerScenarios":"Passing `--weirdness 1.5` or `--style-weight 120` (percent-style values), `--weirdness abc` (NaN), or empty string not hitting the default-return branch — i.e. any value that is not a finite number between 0 and 1.","commonSituations":"Supplying percentages (0–100) from the Suno UI slider instead of fractions (0–1); typos like `1,0` in locales using comma decimals; shell variables expanding to empty/invalid strings.","solutions":["Convert percentages to fractions: divide by 100 (75% → 0.75).","Use a decimal point, not a comma, for fractional values.","Omit the flag to use the built-in default when the value is undefined/null/''.","Check the label in the message to see which slider option failed."],"exampleFix":"// before\nopencli suno generate --prompt \"song\" --weirdness 75\n// after\nopencli suno generate --prompt \"song\" --weirdness 0.75","handlingStrategy":"validation","validationCode":"function inSliderRange(v) { const n = Number(v); return Number.isFinite(n) && n >= 0 && n <= 1; }\nif (!inSliderRange(weirdness)) throw new Error('--weirdness must be a number between 0 and 1');","typeGuard":"function isSliderValue(v) {\n  const n = Number(v);\n  return Number.isFinite(n) && n >= 0 && n <= 1;\n}","tryCatchPattern":"try {\n  await run({ weirdness: clampSlider(rawWeirdness, 'weirdness', 0.5) });\n} catch (err) {\n  if (err.name === 'ArgumentError' && /between 0 and 1/.test(err.message)) {\n    console.warn('Using default slider value');\n  } else throw err;\n}","preventionTips":["Remember the range is 0–1, not 0–100; divide UI percentages by 100.","Use decimal points, never comma decimals.","Omit the flag to accept the default instead of guessing a value.","Clamp programmatically: Math.min(1, Math.max(0, n))."],"tags":["cli","argument-validation","suno"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}