{"record":{"id":"f567863167b6c685","repo":"garrytan/gstack","slug":"usage-screenshot-clip-x-y-width-height-all-mu","errorCode":null,"errorMessage":"Usage: screenshot --clip x,y,width,height — all must be numbers","messagePattern":"Usage: screenshot --clip x,y,width,height — all must be numbers","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"browse/src/meta-commands.ts","lineNumber":460,"sourceCode":"      let viewportOnly = false;\n      let base64Mode = false;\n\n      const remaining: string[] = [];\n      let flagSelector: string | undefined;\n      for (let i = 0; i < args.length; i++) {\n        if (args[i] === '--viewport') {\n          viewportOnly = true;\n        } else if (args[i] === '--base64') {\n          base64Mode = true;\n        } else if (args[i] === '--selector') {\n          flagSelector = args[++i];\n          if (!flagSelector) throw new Error('Usage: screenshot --selector <css> [path]');\n        } else if (args[i] === '--clip') {\n          const coords = args[++i];\n          if (!coords) throw new Error('Usage: screenshot --clip x,y,w,h [path]');\n          const parts = coords.split(',').map(Number);\n          if (parts.length !== 4 || parts.some(isNaN))\n            throw new Error('Usage: screenshot --clip x,y,width,height — all must be numbers');\n          clipRect = { x: parts[0], y: parts[1], width: parts[2], height: parts[3] };\n        } else if (args[i].startsWith('--')) {\n          throw new Error(`Unknown screenshot flag: ${args[i]}`);\n        } else {\n          remaining.push(args[i]);\n        }\n      }\n\n      // Separate target (selector/@ref) from output path\n      for (const arg of remaining) {\n        // File paths containing / and ending with an image/pdf extension are never CSS selectors\n        const isFilePath = arg.includes('/') && /\\.(png|jpe?g|webp|pdf)$/i.test(arg);\n        if (isFilePath) {\n          outputPath = arg;\n        } else if (arg.startsWith('@e') || arg.startsWith('@c') || arg.startsWith('.') || arg.startsWith('#') || arg.includes('[')) {\n          targetSelector = arg;\n        } else {\n          outputPath = arg;","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/browse/src/meta-commands.ts#L442-L478","documentation":"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.","triggerScenarios":"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').","commonSituations":"User uses wrong separator (spaces instead of commas), omits one coordinate, includes units (px), or copies coordinates in a different format from another tool.","solutions":["Provide exactly 4 comma-separated numbers: x,y,width,height (e.g., '0,0,800,600')","Remove any unit suffixes (px, in) — use bare numbers","Ensure values are separated by commas, not spaces or semicolons"],"exampleFix":"# before\n$B screenshot --clip 0 0 800 600 out.png\n# or\n$B screenshot --clip 0,0,800px,600px out.png\n\n# after\n$B screenshot --clip 0,0,800,600 out.png","handlingStrategy":"validation","validationCode":"const idx = args.indexOf('--clip');\nif (idx !== -1 && args[idx + 1]) {\n  const parts = args[idx + 1].split(',').map(Number);\n  if (parts.length !== 4 || parts.some(isNaN)) {\n    throw new Error('--clip requires exactly 4 comma-separated numbers: x,y,width,height');\n  }\n}","typeGuard":"function isValidClipString(v: string): boolean {\n  const parts = v.split(',').map(Number);\n  return parts.length === 4 && parts.every(n => !isNaN(n));\n}","tryCatchPattern":null,"preventionTips":["Format clip coordinates as exactly 4 comma-separated bare numbers (no units)","Validate the coordinate string with a regex like /^\\d+,\\d+,\\d+,\\d+$/ before passing it"],"tags":["screenshot","cli","validation"],"backgroundTag":null,"analyzedSha":"94993f74012782fd94416dd44b8314f6363a13a4","analyzedAt":"2026-08-12T04:06:23.140Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}