jackwener/OpenCLI · error · ArgumentError

--before must be a seq number (got "${before}")

Error message

--before must be a seq number (got "${before}")

What it means

message-read.js validates the optional `--before` cursor: unlike --after it accepts only numeric sequence numbers (no UUIDs). A non-empty value that isn't all digits throws this ArgumentError.

Source

Thrown at clis/slock/message-read.js:55

    { name: 'before', help: 'seq to page before' },
    { name: 'limit', type: 'int', default: 50, help: 'Max messages' },
    { name: 'no-threads', type: 'bool', default: false, help: 'Skip /threads enrichment' },
    { name: 'server', help: 'Override active server' },
  ],
  columns: ['id', 'seq', 'createdAt', 'senderName', 'content', 'threadChannelId', 'replyCount', 'unreadCount', 'lastReplyAt'],
  func: async (page, kwargs) => {
    const channel = String(kwargs.channel ?? '').trim();
    if (!channel) throw new ArgumentError('channel required');
    const tt = classifyThreadTarget(channel);
    const isUuid = UUID_RE.test(channel);
    const after = kwargs.after !== undefined ? String(kwargs.after) : '';
    if (after && !/^\d+$/.test(after) && !UUID_RE.test(after)) {
      throw new ArgumentError(`--after must be a seq number or messageId UUID (got "${after}")`);
    }
    const limit = parsePositiveInteger(kwargs.limit, '--limit', { defaultValue: 50 });
    const before = kwargs.before !== undefined ? String(kwargs.before) : '';
    if (before && !/^\d+$/.test(before)) {
      throw new ArgumentError(`--before must be a seq number (got "${before}")`);
    }
    if (before) parsePositiveInteger(before, '--before');
    const noThreads = !!kwargs['no-threads'];
    // R1 — pass the raw override through to authHeadersFragment; it owns the
    // UUID-vs-slug resolution against /servers/ now.
    const override = kwargs.server ?? null;

    await page.goto(SLOCK_HOME_URL);

    const params = {
      isUuid, channel, after, before, limit, noThreads, override,
      parentTarget: tt?.parentTarget ?? '',
      parentMsgId: tt?.parentMsgId ?? '',
      isThread: !!tt,
    };
    const snippet = buildReadSnippet(params);
    const result = await page.evaluate(`(async () => { ${snippet} })()`);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use the numeric `seq` value with --before; UUIDs are only valid for --after.
  2. Look up the seq of the reference message first, then pass that number.
  3. Trim/normalize the value to digits only.

Example fix

// before
--before 6f1c2e34-9a0b-4c8d-8e2f-1a2b3c4d5e6f
// after
--before 8470
Defensive patterns

Strategy: validation

Validate before calling

if (before != null && before !== '' && !/^\d+$/.test(String(before))) throw new Error(`--before must be a seq number, got: ${before}`);

Type guard

const isValidBefore = (v) => v === undefined || v === '' || /^\d+$/.test(String(v));

Try / catch

try { await readMessages(page, {...kwargs, before}); } catch (e) { if (String(e.message).startsWith('--before must be')) { console.error(`--before accepts only numeric seq; got "${before}"`); } else throw e; }

Prevention

When it happens

Trigger: Passing `--before` with a UUID, timestamp, or any non-numeric string.

Common situations: Assuming --before accepts message UUIDs like --after does; passing a messageId copied from output instead of the seq number.

Related errors


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