jackwener/OpenCLI · error · ArgumentError

channel required

Error message

channel required

What it means

`channel-mark` requires a target channel. The CLI trims the `channel` kwarg and throws ArgumentError('channel required') when it is missing or empty, before deciding the read/unread path suffix.

Source

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

cli({
  site: SLOCK_SITE,
  name: 'channel-mark',
  access: 'write',
  description: 'Mark a channel read (default), read up to --seq, or --unread.',
  domain: SLOCK_DOMAIN,
  strategy: Strategy.COOKIE,
  browser: true,
  siteSession: 'persistent',
  args: [
    { name: 'channel', positional: true, required: true, help: 'channelId UUID or #name' },
    { name: 'seq', type: 'int', help: 'Mark read up to this seq (omit for read-all)' },
    { name: 'unread', type: 'bool', default: false, help: 'Mark the channel unread instead of read' },
    { name: 'server', help: 'Override active server' },
  ],
  columns: ['channel', 'action', 'result'],
  func: async (page, kwargs) => {
    const channel = String(kwargs.channel ?? '').trim();
    if (!channel) throw new ArgumentError('channel required');
    const hasSeq = kwargs.seq !== undefined && kwargs.seq !== null && kwargs.seq !== '';
    if (kwargs.unread && hasSeq) {
      throw new ArgumentError('--unread and --seq are mutually exclusive');
    }

    let pathSuffix;
    let body;
    let action;
    if (kwargs.unread) {
      pathSuffix = '/unread';
      action = 'unread';
    } else if (hasSeq) {
      const seq = Number(kwargs.seq);
      if (!Number.isInteger(seq) || seq <= 0) throw new ArgumentError(`--seq must be a positive integer (got "${kwargs.seq}")`);
      pathSuffix = '/read';
      body = { seq };
      action = `read-to-${seq}`;
    } else {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass the channel: `slock channel-mark --channel '#ops'` (optionally with --seq or --unread)
  2. Skip empty values in loops before invoking the command
  3. Check `slock channel-mark --help` for correct syntax

Example fix

// before
$ slock channel-mark --seq 42
Error: channel required
// after
$ slock channel-mark --channel '#ops' --seq 42
Defensive patterns

Strategy: validation

Validate before calling

const channel = String(input.channel ?? '').trim();
if (!channel) throw new Error('channel must be provided (#name or channelId UUID)');

Type guard

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

Try / catch

try {
  await run(['slock', 'channel-mark', '--channel', channel, ...extra]);
} catch (e) {
  if (e instanceof ArgumentError && e.message === 'channel required') {
    console.error('Pass --channel <#name|uuid>; the value was empty.');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `slock channel-mark` (to mark read/unread) without `--channel`, or with an empty/whitespace-only value.

Common situations: Batch scripts iterating channels where one entry is blank, aliases dropping the flag, or piping a channel list with empty lines.

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