jackwener/OpenCLI · info · EmptyResultError
ctrip hotel-suggest
Error message
ctrip hotel-suggest
What it means
EmptyResultError thrown when the Ctrip suggest endpoint returned data but, after filtering non-objects and rows without a name, no usable suggestions remain. The library treats an empty suggestion set as a user-facing condition worth its own error type rather than returning []. The message suggests alternative keywords.
Source
Thrown at clis/ctrip/hotel-suggest.js:41
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
- Retry with a broader or correctly spelled keyword (e.g. a city or hotel brand)
- Check the --limit value is > 0
- Inspect fetchSuggest output and update mapSuggestRow if the name field moved
- Try a Chinese-language keyword if searching the international site
Example fix
// before
await ctrip.hotelSuggest({ query: 'xqzzy', limit: 0 });
// after
await ctrip.hotelSuggest({ query: '陆家嘴', limit: 10 }); Defensive patterns
Strategy: fallback
Validate before calling
if (!query || !query.trim()) throw new Error('query required');
const limit = Number(kwargs.limit ?? 10);
if (!Number.isInteger(limit) || limit <= 0) throw new Error('limit must be a positive integer'); Type guard
const isNamedSuggestion = (item) => !!item && typeof item === 'object' && typeof item.name === 'string' && item.name.length > 0;
Try / catch
try {
return await ctrip.hotelSuggest({ query });
} catch (e) {
if (e instanceof EmptyResultError) {
return []; // or retry with a broadened keyword
}
throw e;
} Prevention
- Prefer well-known city/area/brand keywords
- Retry with progressively broader queries
- Ensure limit > 0
- Handle EmptyResultError as a normal UX branch, not a crash
When it happens
Trigger: fetchSuggest returns entries that are all null/non-objects or lack a name field, or the endpoint returns an empty array for a query with no matches (misspelled keyword, very obscure location).
Common situations: Searching gibberish or over-specific keywords; Ctrip returning region-gated empty results; API shape change removing the name field from suggest items; slicing with limit 0 via a bad --limit argument.
Understand the failure class
Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.
Related errors
- ctrip package
- ctrip search
- No tour packages for "${destination}"
- No 12306 stations match "${keyword}"
- ${label}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/d3d0a4b9bc362257.
Report an issue: GitHub.