jackwener/OpenCLI · error · ArgumentError
query required
Error message
query required
What it means
message-search.js requires a `query` argument. If the kwarg is missing or trims to an empty string it throws ArgumentError('query required').
Source
Thrown at clis/slock/message-search.js:27
cli({
site: SLOCK_SITE,
name: 'message-search',
access: 'read',
description: 'Search messages',
domain: SLOCK_DOMAIN,
strategy: Strategy.COOKIE,
browser: true,
siteSession: 'persistent',
args: [
{ name: 'query', positional: true, required: true, help: 'Search query' },
{ name: 'channel', help: 'Restrict to a channel (UUID or #name)' },
{ name: 'limit', type: 'int', default: 50, help: 'Max results' },
{ name: 'server', help: 'Override active server' },
],
columns: ['id', 'channelId', 'createdAt', 'senderName', 'content'],
func: async (page, kwargs) => {
const q = String(kwargs.query ?? '').trim();
if (!q) throw new ArgumentError('query required');
const channel = String(kwargs.channel ?? '').trim();
const isUuid = channel ? UUID_RE.test(channel) : false;
const target = channel ? JSON.stringify(channel.replace(/^#/, '').toLowerCase()) : '""';
// R1 — raw override; authHeadersFragment owns the UUID-vs-slug resolution.
const override = kwargs.server ?? null;
const limit = parsePositiveInteger(kwargs.limit, '--limit', { defaultValue: 50 });
await page.goto(SLOCK_HOME_URL);
const snippet = `
${authHeadersFragment({ serverScoped: true, serverIdOverride: override })}
let channelId = '';
if (${JSON.stringify(channel)}) {
if (${isUuid}) {
channelId = ${JSON.stringify(channel)};
} else {
const cres = await fetch('${SLOCK_API_BASE}/channels/', { credentials:'include', headers });
if (!cres.ok) return { kind: cres.status===401?'auth':'http', status: cres.status, where:'/channels/' };
const arr = await cres.json();
const hit = (Array.isArray(arr)?arr:(arr.channels||arr.data||[])).find((c) => (c.name||c.slug||'').toLowerCase() === ${target});View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a search term: e.g. `--query "deploy failure"`.
- Verify the variable feeding the query is non-empty before invoking.
- Check shell quoting so the argument isn't dropped or split.
Example fix
// before
await run('message-search', { channel: '#general' });
// after
await run('message-search', { channel: '#general', query: 'deploy failure' }); Defensive patterns
Strategy: validation
Validate before calling
const q = String(kwargs.query ?? '').trim();
if (!q) throw new Error('message-search: --query is required'); Type guard
const query = typeof kwargs.query === 'string' && kwargs.query.trim() ? kwargs.query.trim() : null;
if (!query) throw new Error('query required'); Try / catch
try { await searchMessages(page, kwargs); } catch (e) { if (e instanceof ArgumentError && e.message === 'query required') { console.error('Usage: message-search --query "term"'); } else throw e; } Prevention
- Always pass a non-empty --query
- Guard dynamic query sources (upstream command output) for emptiness
- Quote queries in shells so they are not dropped
When it happens
Trigger: Invoking the message-search command without `--query`, or with an empty/whitespace-only value.
Common situations: Building the query dynamically from another command whose output was empty; forgetting the flag; quoting issues causing the shell to swallow the argument.
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
- symbol is required
- Either --product-id or --url is required
- --city is required (numeric city ID from `ctrip search` or `
- --${name} is required (e.g. 北京 / 上海)
- hotel id is required (numeric id from `ctrip hotel-suggest`,
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/cbf6dc0e6ecf0266.
Report an issue: GitHub.