{"record":{"id":"35de3681ccccfd07","repo":"garrytan/gstack","slug":"usage-screenshot-clip-x-y-w-h-path","errorCode":null,"errorMessage":"Usage: screenshot --clip x,y,w,h [path]","messagePattern":"Usage: screenshot --clip x,y,w,h \\[path\\]","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"browse/src/meta-commands.ts","lineNumber":457,"sourceCode":"      let outputPath = `${TEMP_DIR}/browse-screenshot.png`;\n      let clipRect: { x: number; y: number; width: number; height: number } | undefined;\n      let targetSelector: string | undefined;\n      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('[')) {","sourceCodeStart":439,"sourceCodeEnd":475,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/browse/src/meta-commands.ts#L439-L475","documentation":"Thrown by the screenshot command when --clip is the last token in argv — the (++i) increment reads undefined. The --clip flag requires a coordinate string in 'x,y,w,h' format to define the crop rectangle.","triggerScenarios":"Passing '--clip' as the final argument with no subsequent value, e.g., 'screenshot --clip'.","commonSituations":"User forgets the coordinate string, or a script omits the value.","solutions":["Provide the coordinate string immediately after --clip, e.g., 'screenshot --clip 0,0,800,600 out.png'","If building the command programmatically, ensure the clip coordinates variable is non-empty"],"exampleFix":"# before\n$B screenshot --clip\n\n# after\n$B screenshot --clip 0,0,800,600 out.png","handlingStrategy":"validation","validationCode":"const idx = args.indexOf('--clip');\nif (idx !== -1 && (idx === args.length - 1 || !args[idx + 1])) {\n  throw new Error('--clip requires a coordinate string');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always provide the x,y,w,h coordinate string immediately after --clip","Validate programmatically constructed commands to ensure no flag is left valueless"],"tags":["screenshot","cli","argument-parsing"],"backgroundTag":null,"analyzedSha":"94993f74012782fd94416dd44b8314f6363a13a4","analyzedAt":"2026-08-12T04:06:23.140Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}