jackwener/OpenCLI · error · ArgumentError

channel required

Error message

channel required

What it means

This ArgumentError is thrown by makeChannelActionCommand's func when the positional `channel` argument is empty after trimming. Channel actions (archive etc.) need a channelId UUID or #name to resolve a channelId server-side; without it the request cannot even be built.

Source

Thrown at clis/slock/channel-action.js:30

// archived channels are excluded from the name lookup (use UUID).
export function makeChannelActionCommand({ name, verb, resultLabel, description, archivedHint = false }) {
  cli({
    site: SLOCK_SITE,
    name,
    access: 'write',
    description,
    domain: SLOCK_DOMAIN,
    strategy: Strategy.COOKIE,
    browser: true,
    siteSession: 'persistent',
    args: [
      { name: 'channel', positional: true, required: true, help: 'channelId UUID or #name' },
      { name: 'server', help: 'Override active server' },
    ],
    columns: ['channel', 'id', 'archivedAt', 'result'],
    func: async (page, kwargs) => {
      const channel = String(kwargs.channel ?? '').trim();
      if (!channel) throw new ArgumentError('channel required');
      await page.goto(SLOCK_HOME_URL);
      const snippet = buildChannelScopedSnippet({
        channelInput: channel,
        method: 'POST',
        pathSuffix: `/${verb}`,
        serverIdOverride: kwargs.server,
      });
      const result = await page.evaluate(`(async () => { ${snippet} })()`);
      let data;
      try {
        data = dispatchEvaluateResult(result);
      } catch (e) {
        // F7 — channelResolveFragment lists active channels only; archived
        // channels are absent from the lookup, so `#name` resolve fails for
        // a channel you're trying to unarchive. UUID still works. Rewrite
        // the bare "no channel matches" message into something actionable.
        if (archivedHint && e instanceof ArgumentError && /no channel matches/.test(e.message)) {
          throw new ArgumentError(

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass the channel as channelId UUID or #name, e.g. `channel-action archive '#general'`.
  2. Check the shell variable feeding the argument is set and non-empty (`echo "$CHANNEL"`).
  3. Resolve the channel first via a channel-list command and use its id or exact #name.
  4. In scripts, guard with `[ -n "$CHANNEL" ] || exit 1` before invoking the CLI.

Example fix

// before
await channelAction(page, { channel: process.env.CH });
// after
if (!process.env.CH?.trim()) throw new Error('CH env var must be a channelId or #name');
await channelAction(page, { channel: process.env.CH });
Defensive patterns

Strategy: validation

Validate before calling

const channel = String(input ?? '').trim();
if (!channel) throw new Error('channel required: pass a channelId UUID or #name');

Type guard

const hasChannelArg = (v) => typeof v === 'string' && v.trim().length > 0;

Try / catch

try {
  await channelAction(page, { channel, verb: 'archive' });
} catch (e) {
  if (e instanceof ArgumentError && e.message === 'channel required') {
    console.error('Provide a channel: UUID or #name (check the shell variable was set)');
  } else throw e;
}

Prevention

When it happens

Trigger: Invoking a channel-action command with the positional argument missing, an empty string, or only whitespace (e.g. a shell variable that expanded to nothing).

Common situations: Shell scripts with unset CHANNEL variables (`channel="" archive`), copy-paste dropping the argument, or pipelines where the channel was never resolved from an earlier step.

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/13fc4247480f182a. Report an issue: GitHub.