jackwener/OpenCLI · error · ArgumentError

coords must be in "x,y" format (e.g. "1,2")

Error message

coords must be in "x,y" format (e.g. "1,2")

What it means

normalizeCoords() splits a coordinate string on commas and requires exactly two trimmed parts, which it then forwards to normalizeNumber as x and y. It throws ArgumentError when the input does not have exactly two comma-separated components, because GeoGebra point placement needs both an x and a y value.

Source

Thrown at clis/geogebra/utils.js:53

  if (parts.length < min || parts.length > max) {
    throw new ArgumentError(`${label} must contain ${min === max ? min : `${min}-${max}`} comma-separated labels`);
  }
  return parts.map((part, idx) => normalizeLabel(part, `${label}[${idx + 1}]`));
}

export function normalizeNumber(value, label, { defaultValue, positive = false } = {}) {
  const raw = value == null || value === '' ? defaultValue : value;
  const number = Number(raw);
  if (!Number.isFinite(number) || (positive && number <= 0)) {
    throw new ArgumentError(`${label} must be a ${positive ? 'positive ' : ''}finite number`);
  }
  return number;
}

export function normalizeCoords(value) {
  const parts = String(value ?? '').split(',').map(s => s.trim());
  if (parts.length !== 2) {
    throw new ArgumentError('coords must be in "x,y" format (e.g. "1,2")');
  }
  return parts.map((part, idx) => normalizeNumber(part, idx === 0 ? 'x' : 'y'));
}

export function requireGgbSuccess(result, message) {
  if (!isPlainObject(result)) {
    throw new CommandExecutionError(`${message}: malformed GeoGebra result`);
  }
  if (!result.ok) {
    throw new CommandExecutionError(result.error || message);
  }
  return result;
}

/**
 * Navigate to GeoGebra Geometry (if not already there) and wait for
 * the ggbApplet API to become available.
 */

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass coordinates exactly as 'x,y' with a comma separator and no extra components (e.g. '1,2').
  2. Use '.' as the decimal separator: '1.5,2.5' not '1,5 2,5'.
  3. If data is an array or object, join it first: [x, y].join(',').
  4. Validate the format before calling: /^\s*-?\d+(\.\d+)?\s*,\s*-?\d+(\.\d+)?\s*$/.test(coords).

Example fix

// before
await placePoint({ coords: [1, 2] });
// after
await placePoint({ coords: '1,2' });
Defensive patterns

Strategy: validation

Validate before calling

const COORD_RE = /^\s*-?\d+(\.\d+)?\s*,\s*-?\d+(\.\d+)?\s*$/;
if (!COORD_RE.test(coords)) throw new Error('coords must be "x,y", e.g. "1,2"');

Type guard

null

Try / catch

try { await placePoint({ coords }); } catch (e) { if (String(e.message).includes('x,y')) { console.error('Use format "1,2" with a comma and decimal points, not commas'); } else throw e; }

Prevention

When it happens

Trigger: Calling any point-creating tool with coords like '1' (missing y), '1,2,3' (extra component), '1;2' (wrong separator), or an empty string — parts.length !== 2 triggers the throw.

Common situations: Users typing coordinates with a space+comma only ('1 ,'), using locale decimal commas ('1,5,2,5' for two decimals), or passing a JSON array instead of the documented 'x,y' string.

Related errors


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