jackwener/OpenCLI · error · ArgumentError

file path required

Error message

file path required

What it means

This ArgumentError is thrown by `attachment-upload` in clis/slock/attachment-upload.js:50 when the `file` argument is missing, empty, or whitespace-only after trimming. The command needs a local file path to read, base64-encode, and hand to the in-page upload snippet, so it fails fast before any browser or network work.

Source

Thrown at clis/slock/attachment-upload.js:50

cli({
  site: SLOCK_SITE,
  name: 'attachment-upload',
  access: 'write',
  description: 'Upload a local file to Slock attachments. Prints the attachmentId for use with `message-send --attach`.',
  domain: SLOCK_DOMAIN,
  strategy: Strategy.COOKIE,
  browser: true,
  siteSession: 'persistent',
  args: [
    { name: 'file', positional: true, required: true, help: 'Local file path to upload (single file; max 50 MB)' },
    { name: 'channel', positional: true, required: true, help: 'channelId UUID or #name — server requires the attachment be scoped to a channel' },
    { name: 'server', help: 'Override active server slug' },
  ],
  columns: ['attachmentId', 'filename', 'mimeType', 'sizeBytes'],
  func: async (page, kwargs) => {
    const filePath = String(kwargs.file ?? '').trim();
    if (!filePath) throw new ArgumentError('file path required');
    const channel = String(kwargs.channel ?? '').trim();
    if (!channel) throw new ArgumentError('channel required (UUID or #name); server rejects uploads without channelId');
    const abs = path.resolve(filePath);
    let stat;
    try { stat = fs.statSync(abs); }
    catch (e) { throw new ArgumentError(`file not readable: ${abs} (${e.message})`); }
    if (!stat.isFile()) throw new ArgumentError(`not a regular file: ${abs}`);
    if (stat.size === 0) throw new ArgumentError(`file is empty: ${abs}`);
    if (stat.size > MAX_BYTES) {
      throw new ArgumentError(`file is ${stat.size} bytes, exceeds server limit ${MAX_BYTES} (50 MiB). Split or compress before upload.`);
    }

    const buf = fs.readFileSync(abs);
    const filename = path.basename(abs);
    const b64 = buf.toString('base64');

    await page.goto(SLOCK_HOME_URL);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass the local file path as the first positional argument: `attachment-upload ./report.pdf #general`.
  2. Check that the variable holding the path is actually set before invoking: `: "${FILE_PATH:?FILE_PATH not set}"`.
  3. If the file is produced by a previous pipeline step, verify that step succeeded and wrote its output before running the upload.

Example fix

// before (shell): unset var silently becomes empty argument
attachment-upload "$FILE_PATH" "$CHANNEL"
// after: fail fast if unset/empty
: "${FILE_PATH:?FILE_PATH not set}"
attachment-upload "$FILE_PATH" "$CHANNEL"
Defensive patterns

Strategy: validation

Validate before calling

const filePath = String(process.argv[2] ?? '').trim();
if (!filePath) {
  throw new Error('file path required: pass the local file as the first argument');
}

Try / catch

try {
  await upload({ file: filePath, channel });
} catch (e) {
  if (e instanceof ArgumentError && e.message === 'file path required') {
    console.error('Usage: attachment-upload <file> <channel>');
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the `attachment-upload` command without the positional `file` argument, passing `--file ''`, or passing a value consisting only of whitespace. Also occurs when a script interpolates an unset variable into the argument position, producing an empty string.

Common situations: Shell scripts where `$FILE_PATH` is unset due to a failed earlier step (empty variable expands to nothing); CI pipelines where an artifact path env var is missing; users running `attachment-upload '' mychannel` expecting the CLI to prompt or default.

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