jackwener/OpenCLI · error · ArgumentError

target required

Error message

target required

What it means

message-send.js requires a `target` argument identifying the destination (channel, DM, etc.). If the kwarg is missing or trims to empty, it throws ArgumentError('target required').

Source

Thrown at clis/slock/message-send.js:29

  name: 'message-send',
  access: 'write',
  description: 'Send a message to a channel, DM, or thread (content sent verbatim)',
  domain: SLOCK_DOMAIN,
  strategy: Strategy.COOKIE,
  browser: true,
  siteSession: 'persistent',
  args: [
    { name: 'target', positional: true, required: true, help: '"#channel", "#channel:msgIdOrShort", "dm:@name", "dm:<uuid>", or channel UUID' },
    { name: 'content', positional: true, required: true, help: 'Message body (sent verbatim, no marker)' },
    { name: 'dry-run', type: 'bool', default: false, help: 'Print the planned payload without sending' },
    { name: 'as-task', type: 'bool', default: false, help: 'Create the message as a task (asTask)' },
    { name: 'attach', help: 'Comma-separated attachmentId UUIDs (upload separately first)' },
    { name: 'server', help: 'Override active server (slug or id)' },
  ],
  columns: ['target', 'channelId', 'content', 'result', 'messageId'],
  func: async (page, kwargs) => {
    const target = String(kwargs.target ?? '').trim();
    if (!target) throw new ArgumentError('target required');
    const content = String(kwargs.content ?? '');
    const asTask = !!kwargs['as-task'];
    const attachmentIds = String(kwargs.attach ?? '')
      .split(',').map((s) => s.trim()).filter(Boolean);
    for (const aid of attachmentIds) {
      if (!UUID_RE.test(aid)) throw new ArgumentError(`--attach expects attachmentId UUIDs; "${aid}" is not a UUID`);
    }
    let cls;
    try { cls = classifyTarget(target); }
    catch (e) { throw new ArgumentError(e.message); }

    const extra = { asTask, attachmentIds };

    if (kwargs['dry-run']) {
      return [{
        target, channelId: '(not resolved in dry-run)', content,
        result: asTask ? 'dry-run (asTask)' : 'dry-run', messageId: null,
      }];

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a target: `--target #general`, a channel UUID, or a DM target form.
  2. Ensure the value sourcing the flag is defined and non-empty.
  3. Check shell quoting so the argument reaches the command.

Example fix

// before
await run('message-send', { content: 'hello' });
// after
await run('message-send', { target: '#general', content: 'hello' });
Defensive patterns

Strategy: validation

Validate before calling

const target = String(kwargs.target ?? '').trim();
if (!target) throw new Error('message-send: --target is required');

Type guard

const target = typeof kwargs.target === 'string' && kwargs.target.trim() ? kwargs.target.trim() : null;
if (!target) throw new Error('target required');

Try / catch

try { await sendMessage(page, kwargs); } catch (e) { if (e instanceof ArgumentError && e.message === 'target required') { console.error('Usage: message-send --target <#slug|uuid|dm> --content "..."'); } else throw e; }

Prevention

When it happens

Trigger: Calling message-send without `--target`, or with `--target ""`/whitespace.

Common situations: Omitting the flag in an automated send; a variable holding the destination is undefined; quoting problems losing 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


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