garrytan/gstack · error · Error

Usage: screenshot --clip x,y,width,height — all must be numb

Error message

Usage: screenshot --clip x,y,width,height — all must be numbers

What it means

Thrown by the screenshot command when the --clip value either does not split into exactly 4 comma-separated parts, or when any part fails Number conversion (returns NaN). The clip rectangle requires exactly four numeric values: x, y, width, height.

Source

Thrown at browse/src/meta-commands.ts:460

      let viewportOnly = false;
      let base64Mode = false;

      const remaining: string[] = [];
      let flagSelector: string | undefined;
      for (let i = 0; i < args.length; i++) {
        if (args[i] === '--viewport') {
          viewportOnly = true;
        } else if (args[i] === '--base64') {
          base64Mode = true;
        } else if (args[i] === '--selector') {
          flagSelector = args[++i];
          if (!flagSelector) throw new Error('Usage: screenshot --selector <css> [path]');
        } else if (args[i] === '--clip') {
          const coords = args[++i];
          if (!coords) throw new Error('Usage: screenshot --clip x,y,w,h [path]');
          const parts = coords.split(',').map(Number);
          if (parts.length !== 4 || parts.some(isNaN))
            throw new Error('Usage: screenshot --clip x,y,width,height — all must be numbers');
          clipRect = { x: parts[0], y: parts[1], width: parts[2], height: parts[3] };
        } else if (args[i].startsWith('--')) {
          throw new Error(`Unknown screenshot flag: ${args[i]}`);
        } else {
          remaining.push(args[i]);
        }
      }

      // Separate target (selector/@ref) from output path
      for (const arg of remaining) {
        // File paths containing / and ending with an image/pdf extension are never CSS selectors
        const isFilePath = arg.includes('/') && /\.(png|jpe?g|webp|pdf)$/i.test(arg);
        if (isFilePath) {
          outputPath = arg;
        } else if (arg.startsWith('@e') || arg.startsWith('@c') || arg.startsWith('.') || arg.startsWith('#') || arg.includes('[')) {
          targetSelector = arg;
        } else {
          outputPath = arg;

View on GitHub (pinned to 94993f7401)

Solutions

  1. Provide exactly 4 comma-separated numbers: x,y,width,height (e.g., '0,0,800,600')
  2. Remove any unit suffixes (px, in) — use bare numbers
  3. Ensure values are separated by commas, not spaces or semicolons

Example fix

# before
$B screenshot --clip 0 0 800 600 out.png
# or
$B screenshot --clip 0,0,800px,600px out.png

# after
$B screenshot --clip 0,0,800,600 out.png
Defensive patterns

Strategy: validation

Validate before calling

const idx = args.indexOf('--clip');
if (idx !== -1 && args[idx + 1]) {
  const parts = args[idx + 1].split(',').map(Number);
  if (parts.length !== 4 || parts.some(isNaN)) {
    throw new Error('--clip requires exactly 4 comma-separated numbers: x,y,width,height');
  }
}

Type guard

function isValidClipString(v: string): boolean {
  const parts = v.split(',').map(Number);
  return parts.length === 4 && parts.every(n => !isNaN(n));
}

Prevention

When it happens

Trigger: Passing a --clip value with fewer or more than 4 comma-separated values (e.g., '0,0,800'), or non-numeric values (e.g., 'a,b,c,d' or '0,0,800px,600px').

Common situations: User uses wrong separator (spaces instead of commas), omits one coordinate, includes units (px), or copies coordinates in a different format from another tool.

Related errors


AI-assisted analysis of garrytan/gstack@94993f7401 (2026-08-12). Data as JSON: /api/errors/f567863167b6c685. Report an issue: GitHub.