jackwener/OpenCLI · error · ArgumentError

--pick label cannot be empty

Error message

--pick label cannot be empty

What it means

findUniquePickerOption normalizes the --pick label (collapse whitespace, trim, lowercase) and throws ArgumentError immediately when the normalized label is empty, since there is nothing meaningful to match picker options against.

Source

Thrown at clis/codex/send.js:11

import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, CommandExecutionError, selectorError } from '@jackwener/opencli/errors';
import { unwrapEvaluateResult } from './_actions.js';
import { conversationSelectionArgs, openCodexConversation } from './sidebar.js';

const PICKER_ITEM_SELECTOR = '[data-list-navigation-item="true"]';

export function findUniquePickerOption(options, rawLabel) {
    const wanted = String(rawLabel ?? '').replace(/\s+/g, ' ').trim().toLowerCase();
    if (!wanted) {
        throw new ArgumentError('--pick label cannot be empty');
    }
    const normalized = options.map((option, index) => ({
        index,
        title: String(option.title ?? ''),
        normalizedTitle: String(option.title ?? '').replace(/\s+/g, ' ').trim().toLowerCase(),
        normalizedText: String(option.text ?? option.title ?? '').replace(/\s+/g, ' ').trim().toLowerCase(),
    }));
    const exact = normalized.filter(item => item.normalizedTitle === wanted);
    if (exact.length === 1) {
        return exact[0];
    }
    if (exact.length > 1) {
        throw new CommandExecutionError(`Picker option "${rawLabel}" is ambiguous.`, `Matches: ${exact.map(item => item.title).join(', ')}`);
    }
    const partial = normalized.filter(item => item.normalizedText.includes(wanted));
    if (partial.length === 1) {
        return partial[0];
    }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Provide a non-empty --pick label matching (a part of) the picker option title.
  2. Validate/trim the pick value before calling and fall back to no --pick if empty.
  3. Check shell quoting and variable expansion so the label isn't dropped.

Example fix

// before
const pick = process.env.PICK; // undefined
codexSend({ pick }); // ArgumentError: --pick label cannot be empty

// after
const pick = (process.env.PICK || '').trim();
codexSend(pick ? { pick } : {});
Defensive patterns

Strategy: validation

Validate before calling

const pick = String(kwargs.pick ?? '').trim();
if (kwargs.pick != null && !pick) {
  throw new Error('--pick given but empty; omit it or provide a label');
}

Type guard

function isValidPickLabel(v) {
  return v == null || (typeof v === 'string' && v.trim().length > 0);
}

Try / catch

try {
  await codexSend({ text, pick });
} catch (e) {
  if (e instanceof ArgumentError && /--pick/.test(e.message)) {
    console.error('Fix or drop the --pick flag.');
    process.exitCode = 2;
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling sendCommand (which calls findUniquePickerOption) with rawLabel being null/undefined, an empty string, or a string of only whitespace such as '--pick " "'.

Common situations: Passing an unset shell variable as --pick "$PICK"; quoting mistakes that drop the value; programmatically passing kwargs.pick = '' ; whitespace-only label copied from UI text.

Related errors


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