garrytan/gstack · error · Error

Usage: browse tab <id>

Error message

Usage: browse tab <id>

What it means

Thrown by the 'tab' meta-command when parseInt(args[0], 10) returns NaN — the argument is missing, empty, or non-numeric. The command requires a valid integer tab ID to switch to.

Source

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

  shutdown: () => Promise<void> | void,
  tokenInfo?: TokenInfo | null,
  opts?: MetaCommandOpts,
): Promise<string> {
  // Per-tab operations use the active session; global operations use bm directly
  const session = bm.getActiveSession();

  switch (command) {
    // ─── Tabs ──────────────────────────────────────────
    case 'tabs': {
      const tabs = await bm.getTabListWithTitles();
      return tabs.map(t =>
        `${t.active ? '→ ' : '  '}[${t.id}] ${t.title || '(untitled)'} — ${t.url}`
      ).join('\n');
    }

    case 'tab': {
      const id = parseInt(args[0], 10);
      if (isNaN(id)) throw new Error('Usage: browse tab <id>');
      bm.switchTab(id);
      return `Switched to tab ${id}`;
    }

    case 'newtab': {
      // --json returns structured output (machine-parseable). Other flag-like
      // tokens are treated as the url. make-pdf always passes --json.
      let url: string | undefined;
      let jsonMode = false;
      for (const a of args) {
        if (a === '--json') { jsonMode = true; }
        else if (!url) { url = a; }
      }
      const id = await bm.newTab(url);
      if (jsonMode) {
        return JSON.stringify({ tabId: id, url: url ?? null });
      }
      return `Opened tab ${id}${url ? ` → ${url}` : ''}`;

View on GitHub (pinned to 94993f7401)

Solutions

  1. Run 'browse tabs' first to see the list of open tabs with their numeric IDs
  2. Pass the integer ID shown in the tab list, e.g., 'browse tab 2'
  3. If scripting, ensure the tab ID variable is a number before formatting the command

Example fix

# before
$B tab abc

# after
$B tabs   # see: [0] ..., [1] ..., [2] ...
$B tab 2
Defensive patterns

Strategy: validation

Validate before calling

const id = parseInt(args[0], 10);
if (isNaN(id)) {
  throw new Error('Tab ID must be a number. Run "browse tabs" to list IDs.');
}

Type guard

function isValidTabId(arg: string | undefined): arg is string {
  return arg !== undefined && /^\d+$/.test(arg);
}

Prevention

When it happens

Trigger: Calling 'browse tab' with zero arguments, or with a non-numeric argument like 'browse tab abc' or 'browse tab active'.

Common situations: User forgets the tab ID, passes a tab title or URL instead of the numeric ID, or a script passes an undefined/null value that serializes to a non-numeric string.

Related errors


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