jackwener/OpenCLI · error · ArgumentError

eastmoney convertible --limit must be an integer between 1 a

Error message

eastmoney convertible --limit must be an integer between 1 and 100

What it means

parseConvertibleLimit() normalizes the --limit option (default 20, valid range 1–100). When given a number it must be an integer within 1..100; otherwise it throws ArgumentError. Line 50 fires when a numeric value is passed that is a non-integer (e.g. 2.5) or out of range (0, -1, 101, NaN).

Source

Thrown at clis/eastmoney/convertible.js:50

  if (value === '-') return value;
  throw new CommandExecutionError(`eastmoney convertible returned malformed ${field} for ${bondCode || 'unknown bond'}`);
}

function normalizeEastmoneyString(value, field, bondCode) {
  if (isEastmoneyScalar(value)) return String(value);
  throw new CommandExecutionError(`eastmoney convertible returned malformed ${field} for ${bondCode || 'unknown bond'}`);
}

function normalizeEastmoneyIdentityString(value, field, bondCode) {
  if (typeof value === 'string' && value.trim()) return value;
  throw new CommandExecutionError(`eastmoney convertible returned malformed ${field} for ${bondCode || 'unknown bond'}`);
}

export function parseConvertibleLimit(value) {
  if (value === undefined || value === null || value === '') return 20;
  if (typeof value === 'number') {
    if (Number.isInteger(value) && value >= 1 && value <= 100) return value;
    throw new ArgumentError('eastmoney convertible --limit must be an integer between 1 and 100');
  }
  const raw = String(value).trim();
  if (!/^\d+$/.test(raw)) throw new ArgumentError('eastmoney convertible --limit must be an integer between 1 and 100');
  const parsed = Number(raw);
  if (parsed < 1 || parsed > 100) throw new ArgumentError('eastmoney convertible --limit must be an integer between 1 and 100');
  return parsed;
}

export function extractConvertibleDiff(data) {
  if (!data || typeof data !== 'object' || Array.isArray(data)) {
    throw new CommandExecutionError('eastmoney convertible returned a malformed response envelope');
  }
  if (!data.data || typeof data.data !== 'object' || Array.isArray(data.data)) {
    throw new CommandExecutionError('eastmoney convertible returned a malformed data envelope');
  }
  const diff = data.data.diff;
  if (!Array.isArray(diff)) {
    throw new CommandExecutionError('eastmoney convertible returned malformed diff data');

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass an integer between 1 and 100 inclusive.
  2. Use Math.round/Math.floor on computed values before passing.
  3. Omit --limit entirely to use the default of 20.
  4. Clamp user input to the 1..100 range in your own code first.

Example fix

// before
const limit = Math.ceil(total / pages); // may be float or out of range
// after
const limit = Math.min(100, Math.max(1, Math.round(total / pages) || 20));
Defensive patterns

Strategy: validation

Validate before calling

function validLimit(n) { return Number.isInteger(n) && n >= 1 && n <= 100; }
if (!validLimit(limit)) limit = 20;

Type guard

const isValidLimit = (v) => (typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 100) || (typeof v === 'string' && /^\d+$/.test(v.trim()) && Number(v) >= 1 && Number(v) <= 100);

Try / catch

try {
  rows = await eastmoneyConvertible({ limit });
} catch (e) {
  if (e instanceof ArgumentError && /--limit/.test(e.message)) {
    console.error('Invalid --limit: use an integer 1-100 (default 20).');
  } else throw e;
}

Prevention

When it happens

Trigger: --limit=0, --limit=101, --limit=2.5, or programmatically passing NaN (which is typeof 'number', fails Number.isInteger) to the convertible command.

Common situations: Scripting the CLI with a computed limit that divides to a float; off-by-one when wanting 'all rows' and passing 0 or a huge number; NaN leaking from parseInt on bad input.

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/2542d487205d41f8. Report an issue: GitHub.