jackwener/OpenCLI · error · ArgumentError

${label} must be a number between 0 and 1

Error message

${label} must be a number between 0 and 1

What it means

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.

Source

Thrown at clis/suno/utils.js:105

    if (!Number.isInteger(n) || n < 1) {
        throw new ArgumentError(`${label} must be a positive integer`);
    }
    return n;
}

export function requireNonNegativeInt(value, label) {
    const n = Number(value);
    if (!Number.isInteger(n) || n < 0) {
        throw new ArgumentError(`${label} must be a non-negative integer`);
    }
    return n;
}

export function clampSlider(value, label, def) {
    if (value === undefined || value === null || value === '') return def;
    const n = Number(value);
    if (!Number.isFinite(n) || n < 0 || n > 1) {
        throw new ArgumentError(`${label} must be a number between 0 and 1`);
    }
    return n;
}

// ─────────────────────────────────────────────────────────────────────────────
// In-page helper snippets. Each is inlined into a page.evaluate() call so
// the browser-token is generated fresh per request and the Clerk token is
// pulled live (avoiding 60s TTL expiry on long polls).
// ─────────────────────────────────────────────────────────────────────────────

const BROWSER_TOKEN_JS = `JSON.stringify({ token: btoa(JSON.stringify({ timestamp: Date.now() })) })`;
const CLERK_TOKEN_JS = `await window.Clerk.session.getToken()`;

/**
 * Build the standard header set used by every studio-api-prod.suno.com call.
 *
 * deviceId is read once per command and embedded literally; browser-token
 * and Authorization are computed inline (timestamp/JWT refresh per call).

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Convert percentages to fractions: divide by 100 (75% → 0.75).
  2. Use a decimal point, not a comma, for fractional values.
  3. Omit the flag to use the built-in default when the value is undefined/null/''.
  4. Check the label in the message to see which slider option failed.

Example fix

// before
opencli suno generate --prompt "song" --weirdness 75
// after
opencli suno generate --prompt "song" --weirdness 0.75
Defensive patterns

Strategy: validation

Validate before calling

function inSliderRange(v) { const n = Number(v); return Number.isFinite(n) && n >= 0 && n <= 1; }
if (!inSliderRange(weirdness)) throw new Error('--weirdness must be a number between 0 and 1');

Type guard

function isSliderValue(v) {
  const n = Number(v);
  return Number.isFinite(n) && n >= 0 && n <= 1;
}

Try / catch

try {
  await run({ weirdness: clampSlider(rawWeirdness, 'weirdness', 0.5) });
} catch (err) {
  if (err.name === 'ArgumentError' && /between 0 and 1/.test(err.message)) {
    console.warn('Using default slider value');
  } else throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/db9ea3094b123087. Report an issue: GitHub.