jackwener/OpenCLI · error · ArgumentError
--${name} is required (a destination or attraction keyword)
Error message
--${name} is required (a destination or attraction keyword) What it means
parseKeyword enforces that keyword options (--query, --from, --to, --country, --city) are present and non-blank. If the value is undefined, null, or only whitespace, an ArgumentError is thrown with the option name embedded in the message. The library requires a search keyword because all attraction/destination searches are built from this string.
Source
Thrown at clis/trip/utils.js:401
if (/captcha|verify you are human|security check/i.test(document.body?.innerText || '')) return 'captcha';
const dr = window.__NEXT_DATA__?.props?.pageProps?.hotelDetailResponse;
if (dr && dr.hotelBaseInfo && dr.hotelBaseInfo.nameInfo) return 'content';
return null;
};
const found = detect();
if (found) return resolve(found);
const observer = new MutationObserver(() => {
const result = detect();
if (result) { observer.disconnect(); resolve(result); }
});
observer.observe(document.documentElement, { childList: true, subtree: true });
setTimeout(() => { observer.disconnect(); resolve('timeout'); }, 12000);
})
`;
export function parseKeyword(name, raw) {
if (raw === undefined || raw === null || String(raw).trim() === '') {
throw new ArgumentError(`--${name} is required (a destination or attraction keyword)`);
}
const value = String(raw).trim();
if (value.length > 60) {
throw new ArgumentError(`--${name} is too long (max 60 chars): ${JSON.stringify(raw)}`);
}
return value;
}
export function buildAttractionSearchUrl(keyword) {
const params = new URLSearchParams({ keyword, locale: 'en_US', curr: 'USD' });
return `https://www.trip.com/things-to-do/list?${params.toString()}`;
}
/**
* Browser-context IIFE that extracts attraction / experience rows from Trip.com's
* things-to-do results. The product cards use hashed CSS-module class names, so
* this anchors on the one stable handle each card exposes, the
* `things-to-do/detail/<id>` link (name is its text, `url` its href), and readsView on GitHub (pinned to 49907e53dc)
Solutions
- Pass a non-empty keyword, e.g. --query "Tokyo Tower"
- Echo the shell variable before the call to confirm it is set and non-blank
- Add a default or guard in the calling script: [ -n "$KEYWORD" ] || { echo 'KEYWORD required'; exit 1; }
- Fix the config file/CI variable so the keyword field is populated
Example fix
// before tripcli attractions-search --query "$QUERY" # QUERY is empty // after export QUERY="Santorini" tripcli attractions-search --query "$QUERY"
Defensive patterns
Strategy: validation
Validate before calling
if (keyword === undefined || keyword === null || String(keyword).trim() === '') {
throw new Error('keyword is required');
} Type guard
const hasKeyword = (v) => v !== undefined && v !== null && String(v).trim() !== '';
Try / catch
try {
await runCli(['attractions-search', '--query', keyword]);
} catch (e) {
if (/is required \(a destination or attraction keyword\)/.test(e.message)) {
console.error(`Missing --query. Provide a search keyword.`);
process.exitCode = 2;
return;
}
throw e;
} Prevention
- Use shell parameter expansion defaults: ${KEYWORD:?KEYWORD required}
- Assert config fields exist before invoking the CLI
- Echo/validate env-sourced values before the call
- Keep required flags explicit in scripts rather than conditionally omitted
When it happens
Trigger: Omitting a required --query/--from/--to/--country/--city flag; passing an empty string ('' or ' '); a shell variable that expands to nothing (e.g. --query "$KEYWORD" with KEYWORD unset); a config file key missing so the flag is dropped.
Common situations: Scripting with unset environment variables; YAML/JSON config typos where a keyword field is absent; CI pipelines where the search term comes from an empty secret or artifact; copy-paste commands with a placeholder left in and then deleted.
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
- keyword must not be empty
- <from> station must not be empty
- <to> station must not be empty
- who 不能为空
- key is required
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/98b944ab9ec92cd1.
Report an issue: GitHub.