jackwener/OpenCLI · error · ArgumentError

channel required

Error message

channel required

What it means

task-create requires a `channel` option identifying the target channel; the func trims the value and throws ArgumentError when it is empty. The channel is resolved later via channelResolveFragment, but emptiness is rejected up front.

Source

Thrown at clis/slock/task-create.js:42

cli({
  site: SLOCK_SITE,
  name: 'task-create',
  access: 'write',
  description: 'Create a task in a channel (single title; batch 1-50 is server-supported but client surface is single — see backlog R4).',
  domain: SLOCK_DOMAIN,
  strategy: Strategy.COOKIE,
  browser: true,
  siteSession: 'persistent',
  args: [
    { name: 'channel', positional: true, required: true, help: 'channelId UUID or #name' },
    { name: 'title', positional: true, required: true, help: 'Task title (single; batch TODO via R4)' },
    { name: 'desc', help: 'Optional description body for the task' },
    { name: 'server', help: 'Override active server' },
  ],
  columns: ['id', 'taskNumber', 'title', 'taskStatus', 'channelId'],
  func: async (page, kwargs) => {
    const channel = String(kwargs.channel ?? '').trim();
    if (!channel) throw new ArgumentError('channel required');
    const title = String(kwargs.title ?? '').trim();
    if (!title) throw new ArgumentError('title required (non-empty)');
    const desc = kwargs.desc != null ? String(kwargs.desc) : '';
    await page.goto(SLOCK_HOME_URL);
    const taskObj = desc ? { title, description: desc } : { title };
    const snippet = `
      ${authHeadersFragment({ serverScoped: true, serverIdOverride: kwargs.server })}
      ${channelResolveFragment(channel)}
      // Body is always a batch array — N=1 here because the CLI exposes one
      // title at a time (R4 will widen this). Keep the wrapper so the server
      // sees the same shape as a real batch and we don't fork the contract.
      const body = { tasks: [${JSON.stringify(taskObj)}] };
      const res = await fetch('${SLOCK_API_BASE}/tasks/channel/' + encodeURIComponent(channelId), {
        method:'POST', credentials:'include', headers, body: JSON.stringify(body),
      });
      if (res.status === 400) {
        const j = await res.json().catch(() => ({}));
        return { kind: 'http', status: 400, where: '/tasks/channel/:id (bad request: ' + (j.error || j.message || 'title/limit/shape') + ')' };

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass --channel with the channel name/slug, e.g. --channel general.
  2. Check wrapper scripts/aliases actually forward the --channel flag.
  3. Verify the config or env value supplying the channel is populated.

Example fix

// before
slock task-create --title "Fix bug"
// after
slock task-create --channel general --title "Fix bug"
Defensive patterns

Strategy: validation

Validate before calling

const channel = String(opts.channel ?? '').trim();
if (!channel) throw new Error('channel is required for task-create');

Type guard

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

Try / catch

try {
  await cli('task-create', ['--channel', channel, '--title', title]);
} catch (e) {
  if (e instanceof ArgumentError && e.message === 'channel required') {
    console.error('Pass --channel <slug>; see channel list for valid slugs.');
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Running task-create without --channel, or with --channel set to an empty/whitespace string.

Common situations: Forgetting the flag in an alias or wrapper script; a config file missing the channel key so the interpolated value is empty; renaming a channel in config but leaving the variable unset.

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/0aee1703fc2f287f. Report an issue: GitHub.