jackwener/OpenCLI · warning · ArgumentError

Search keyword cannot be empty

Error message

Search keyword cannot be empty

What it means

ArgumentError thrown by ctrip hotel-suggest when the query argument is missing, empty, or only whitespace. The command requires a non-empty search keyword to call Ctrip's suggest endpoint; the library normalizes the input with String(...).trim() and rejects anything that trims to ''. This is a client-side input validation error, not a network one.

Source

Thrown at clis/ctrip/hotel-suggest.js:31

    site: 'ctrip',
    name: 'hotel-suggest',
    access: 'read',
    description: '搜索携程酒店上下文联想:城市、商圈、单酒店匹配',
    strategy: Strategy.PUBLIC,
    browser: false,
    args: [
        { name: 'query', required: true, positional: true, help: 'Search keyword (city, business area, or hotel name)' },
        { 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, 'H');
        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 hotel-suggest', 'Try a city, business area, or hotel keyword such as "陆家嘴" or "汉庭酒店"');
        }
        return rows;
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a non-empty query, e.g. --query "陆家嘴"
  2. Trim and check user input before invoking the command
  3. Check the flag/kwargs name is exactly query

Example fix

// before
await ctrip.hotelSuggest({ query: process.argv[3] }); // undefined if flag missing
// after
const q = (process.argv[3] || '').trim();
if (!q) throw new Error('usage: --query <keyword>');
await ctrip.hotelSuggest({ query: q });
Defensive patterns

Strategy: validation

Validate before calling

const q = String(kwargs.query ?? '').trim();
if (!q) throw new Error('query is required and cannot be empty');
await ctrip.hotelSuggest({ query: q });

Type guard

const isValidQuery = (q) => typeof q === 'string' && q.trim().length > 0;

Try / catch

try {
  const suggestions = await ctrip.hotelSuggest({ query });
} catch (e) {
  if (e instanceof ArgumentError) {
    console.error('Provide a non-empty --query, e.g. --query "陆家嘴"');
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the hotel-suggest command with no query kwarg, query: '' or query: ' ', or passing a non-string (null/undefined/number) that String()-coerces to empty.

Common situations: Forgetting the --query flag in a script; piping an empty variable from shell expansion; passing null from upstream code; typos like --q instead of --query.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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