jackwener/OpenCLI · error · ArgumentError

Search keyword cannot be empty

Error message

Search keyword cannot be empty

What it means

An ArgumentError thrown by the `ctrip search` command when the `query` argument is missing, an empty string, or only whitespace. The library normalizes the input with String(kwargs.query || '').trim() and rejects falsy/blank keywords up front rather than sending a useless request to Ctrip's suggest API.

Source

Thrown at clis/ctrip/search.js:27

    site: 'ctrip',
    name: 'search',
    access: 'read',
    description: '搜索携程目的地、景区、火车站和地标联想结果',
    strategy: Strategy.PUBLIC,
    browser: false,
    args: [
        { name: 'query', required: true, positional: true, help: 'Search keyword (city, scenic spot, landmark)' },
        { name: 'limit', default: 15, help: 'Number of results (1-50)' },
    ],
    columns: [
        'rank', 'id', 'type', 'displayType', 'name', 'eName',
        'cityId', 'cityName', 'provinceName', 'countryName',
        'lat', 'lon', 'score', 'url',
    ],
    func: async (kwargs) => {
        const query = String(kwargs.query || '').trim();
        if (!query) {
            throw new ArgumentError('Search keyword cannot be empty');
        }
        const limit = parseLimit(kwargs.limit);
        const raw = await fetchSuggest(query, 'D');
        const rows = raw
            .filter((item) => !!item && typeof item === 'object')
            .slice(0, limit)
            .map(mapSuggestRow)
            .filter((row) => row.name);
        if (!rows.length) {
            throw new EmptyResultError('ctrip search', 'Try a destination, scenic spot, or landmark keyword such as "苏州" or "故宫"');
        }
        return rows;
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a non-empty destination or landmark keyword, e.g. `opencli ctrip search 苏州`
  2. Trim and check the keyword in your calling script before invoking the command
  3. Quote shell variables so empty values become explicit errors you can catch: opencli ctrip search "$QUERY"
  4. If input comes from a file/stdin, filter out blank lines before calling

Example fix

// before
await runCli('ctrip', 'search', query);
// after
const q = String(query || '').trim();
if (!q) throw new Error('ctrip search: query cannot be empty');
await runCli('ctrip', 'search', q);
Defensive patterns

Strategy: validation

Validate before calling

const q = String(kwargs.query || '').trim();
if (!q) throw new Error('ctrip search requires a non-empty query');

Type guard

function hasQuery(k) {
  return typeof k.query === 'string' && k.query.trim().length > 0;
}

Try / catch

try {
  const rows = await runCli('ctrip', 'search', q);
} catch (e) {
  if (e.name === 'ArgumentError' && e.message.includes('cannot be empty')) {
    console.error('Provide a destination keyword, e.g. 苏州');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `opencli ctrip search ""`, `opencli ctrip search` with the positional omitted, or programmatically invoking the registered command with kwargs.query = undefined/null/' '.

Common situations: Shell variable expansion to empty ($Q unset with unquoted usage); piping scripts that pass blank lines; forgetting the required positional argument; programmatic wrappers that forward empty user input.

Related errors


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