{"record":{"id":"8eb735fc65b992d1","repo":"jackwener/OpenCLI","slug":"search-keyword-cannot-be-empty-8eb735","errorCode":null,"errorMessage":"Search keyword cannot be empty","messagePattern":"Search keyword cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/ctrip/search.js","lineNumber":27,"sourceCode":"    site: 'ctrip',\n    name: 'search',\n    access: 'read',\n    description: '搜索携程目的地、景区、火车站和地标联想结果',\n    strategy: Strategy.PUBLIC,\n    browser: false,\n    args: [\n        { name: 'query', required: true, positional: true, help: 'Search keyword (city, scenic spot, landmark)' },\n        { name: 'limit', default: 15, help: 'Number of results (1-50)' },\n    ],\n    columns: [\n        'rank', 'id', 'type', 'displayType', 'name', 'eName',\n        'cityId', 'cityName', 'provinceName', 'countryName',\n        'lat', 'lon', 'score', 'url',\n    ],\n    func: async (kwargs) => {\n        const query = String(kwargs.query || '').trim();\n        if (!query) {\n            throw new ArgumentError('Search keyword cannot be empty');\n        }\n        const limit = parseLimit(kwargs.limit);\n        const raw = await fetchSuggest(query, 'D');\n        const rows = raw\n            .filter((item) => !!item && typeof item === 'object')\n            .slice(0, limit)\n            .map(mapSuggestRow)\n            .filter((row) => row.name);\n        if (!rows.length) {\n            throw new EmptyResultError('ctrip search', 'Try a destination, scenic spot, or landmark keyword such as \"苏州\" or \"故宫\"');\n        }\n        return rows;\n    },\n});\n","sourceCodeStart":9,"sourceCodeEnd":42,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/ctrip/search.js#L9-L42","documentation":"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.","triggerScenarios":"Calling `opencli ctrip search \"\"`, `opencli ctrip search` with the positional omitted, or programmatically invoking the registered command with kwargs.query = undefined/null/'   '.","commonSituations":"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.","solutions":["Pass a non-empty destination or landmark keyword, e.g. `opencli ctrip search 苏州`","Trim and check the keyword in your calling script before invoking the command","Quote shell variables so empty values become explicit errors you can catch: opencli ctrip search \"$QUERY\"","If input comes from a file/stdin, filter out blank lines before calling"],"exampleFix":"// before\nawait runCli('ctrip', 'search', query);\n// after\nconst q = String(query || '').trim();\nif (!q) throw new Error('ctrip search: query cannot be empty');\nawait runCli('ctrip', 'search', q);","handlingStrategy":"validation","validationCode":"const q = String(kwargs.query || '').trim();\nif (!q) throw new Error('ctrip search requires a non-empty query');","typeGuard":"function hasQuery(k) {\n  return typeof k.query === 'string' && k.query.trim().length > 0;\n}","tryCatchPattern":"try {\n  const rows = await runCli('ctrip', 'search', q);\n} catch (e) {\n  if (e.name === 'ArgumentError' && e.message.includes('cannot be empty')) {\n    console.error('Provide a destination keyword, e.g. 苏州');\n  } else throw e;\n}","preventionTips":["Always trim and non-empty-check user input before invoking","Quote shell variables (\"$Q\") so empty values fail loudly in your code","Filter blank lines when batching keywords from files/stdin","Validate required positionals in wrapper scripts"],"tags":["validation","argument-error","input-validation","ctrip"],"backgroundTag":"missing-or-empty-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}