jackwener/OpenCLI · error · ArgumentError

timeout must be a positive integer

Error message

timeout must be a positive integer

What it means

ArgumentError thrown when the --timeout keyword is not a positive integer. Number(kwargs.timeout ?? 120) is checked with Number.isInteger(timeout) && timeout > 0 before being used for waitForAnswer.

Source

Thrown at clis/qwen/ask.js:44

    browser: true,
    siteSession: 'persistent',
    navigateBefore: false,
    defaultFormat: 'plain',
    args: [
        { name: 'prompt', required: true, positional: true, help: 'Prompt to send to Qianwen' },
        { name: 'timeout', type: 'int', default: 120, help: 'Max seconds to wait for the response' },
        { name: 'new', type: 'boolean', default: false, help: 'Start a new chat before sending' },
        { name: 'think', type: 'boolean', default: false, help: 'Enable 深度思考 (DeepThink)' },
        { name: 'research', type: 'boolean', default: false, help: 'Enable 深度研究 (DeepResearch)' },
        { name: 'markdown', type: 'boolean', default: false, help: 'Emit assistant reply as markdown' },
    ],
    columns: ['Role', 'Text'],
    func: async (page, kwargs) => {
        const prompt = String(kwargs.prompt || '').trim();
        if (!prompt) throw new ArgumentError('prompt is required');
        const timeout = Number(kwargs.timeout ?? 120);
        if (!Number.isInteger(timeout) || timeout <= 0) {
            throw new ArgumentError('timeout must be a positive integer');
        }
        const startFresh = normalizeBooleanFlag(kwargs.new, false);
        const useThink = normalizeBooleanFlag(kwargs.think, false);
        const useResearch = normalizeBooleanFlag(kwargs.research, false);
        const wantMarkdown = normalizeBooleanFlag(kwargs.markdown, false);

        await ensureOnQianwen(page);
        await dismissLoginModal(page);

        if (startFresh) {
            await startNewChat(page);
            await dismissLoginModal(page);
        }

        if (useThink) await setFeatureToggle(page, 'think', true);
        if (useResearch) await setFeatureToggle(page, 'research', true);

        // Anchor on the visible transcript BEFORE sending so waitForAnswer can

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass an integer number of seconds, e.g. --timeout 180.
  2. Convert durations in your wrapper script before invoking (2m -> 120).
  3. Default to the built-in 120 by omitting --timeout.

Example fix

// before
qwen ask --prompt "hi" --timeout 2m
// after
qwen ask --prompt "hi" --timeout 120
Defensive patterns

Strategy: validation

Validate before calling

const t = Number(process.argv.timeout ?? 120);
if (!Number.isInteger(t) || t <= 0) { console.error('--timeout must be a positive integer (seconds)'); process.exit(2); }

Type guard

function isValidTimeout(v) {
  const n = Number(v);
  return Number.isInteger(n) && n > 0;
}

Try / catch

try {
  await qwenAsk(page, { prompt, timeout: t });
} catch (e) {
  if (e instanceof ArgumentError && /timeout/.test(e.message)) {
    console.error('Pass timeout as integer seconds, e.g. --timeout 180');
  } else { throw e; }
}

Prevention

When it happens

Trigger: --timeout passed as a non-numeric string, a float (e.g. 2.5), zero, or a negative number.

Common situations: Passing '120s' or '2m' instead of seconds; locale-formatted numbers; typo like '--timeout 0'; passing a string with units from a config file.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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