{"record":{"id":"4c3d61f28c9e25a3","repo":"jackwener/OpenCLI","slug":"timeout-must-be-a-positive-integer-seconds-4c3d61","errorCode":null,"errorMessage":"--timeout must be a positive integer (seconds)","messagePattern":"--timeout must be a positive integer \\(seconds\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/cursor/ask.js","lineNumber":20,"sourceCode":"import { ArgumentError, selectorError } from '@jackwener/opencli/errors';\nexport const askCommand = cli({\n    site: 'cursor',\n    name: 'ask',\n    access: 'write',\n    description: 'Send a prompt and wait for the AI response (send + wait + read)',\n    domain: 'localhost',\n    strategy: Strategy.UI,\n    browser: true,\n    args: [\n        { name: 'text', required: true, positional: true, help: 'Prompt to send' },\n        { name: 'timeout', type: 'int', required: false, help: 'Max seconds to wait for response (default: 30)', default: 30 },\n    ],\n    columns: ['Role', 'Text'],\n    func: async (page, kwargs) => {\n        const text = kwargs.text;\n        const timeout = kwargs.timeout;\n        if (!Number.isInteger(timeout) || timeout < 1) {\n            throw new ArgumentError('--timeout must be a positive integer (seconds)');\n        }\n        // Count existing messages before sending\n        const beforeCount = await page.evaluate(`\n      document.querySelectorAll('[data-message-role]').length\n    `);\n        // Inject text into the active editor and submit\n        const injected = await page.evaluate(`(function(text) {\n        let editor = document.querySelector('.aislash-editor-input, [data-lexical-editor=\"true\"], [contenteditable=\"true\"]');\n        if (!editor) return false;\n        editor.focus();\n        document.execCommand('insertText', false, text);\n        return true;\n      })(${JSON.stringify(text)})`);\n        if (!injected)\n            throw selectorError('Cursor input element');\n        await page.wait(0.5);\n        await page.pressKey('Enter');\n        // Poll until a new assistant message appears or timeout","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/cursor/ask.js#L2-L38","documentation":"The cursor `ask` command sends a prompt to the Cursor chat page in a browser session and requires an explicit --timeout in whole seconds. If kwargs.timeout is not an integer >= 1 (missing, fractional, zero, negative, or a non-number), it throws ArgumentError '--timeout must be a positive integer (seconds)' before touching the page, so a bad timeout cannot cause an infinite or zero-length wait.","triggerScenarios":"Calling the ask command with --timeout omitted (undefined), --timeout 0, --timeout -5, --timeout 2.5, or a string like '10' that was never converted to a number.","commonSituations":"Users expecting a default timeout and omitting the flag, passing decimal seconds assuming milliseconds are allowed, or scripts forwarding CLI strings without numeric parsing.","solutions":["Pass --timeout as a positive integer of seconds, e.g. --timeout 30.","Convert and validate before invoking: Number.isInteger(Number(raw)) && Number(raw) >= 1.","Round or floor fractional values: Math.max(1, Math.round(seconds)).","Do not pass 0 or negatives to mean 'no timeout'; choose a finite positive value."],"exampleFix":"// before\ncursor ask --text \"hi\" --timeout 2.5\n// after\ncursor ask --text \"hi\" --timeout 3","handlingStrategy":"validation","validationCode":"const timeout = Number(rawTimeout);\nif (!Number.isInteger(timeout) || timeout < 1) {\n  throw new Error('--timeout must be a positive integer (seconds)');\n}","typeGuard":"const isValidTimeout = (v) => Number.isInteger(v) && v >= 1;","tryCatchPattern":"try {\n  await ask(page, { text, timeout });\n} catch (e) {\n  if (e instanceof ArgumentError && e.message.includes('--timeout')) {\n    console.error('Pass e.g. --timeout 30 (whole seconds).');\n  } else throw e;\n}","preventionTips":["Always pass an explicit integer timeout with ask commands.","Parse CLI strings with Number() and validate integer-ness before forwarding.","Round fractional durations with Math.round and enforce a minimum of 1 second."],"tags":["cli","validation","argument-error","timeout"],"backgroundTag":"invalid-cli-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}