{"record":{"id":"b09d6e8e8ea5ed66","repo":"jackwener/OpenCLI","slug":"file-path-required","errorCode":null,"errorMessage":"file path required","messagePattern":"file path required","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/slock/attachment-upload.js","lineNumber":50,"sourceCode":"\ncli({\n  site: SLOCK_SITE,\n  name: 'attachment-upload',\n  access: 'write',\n  description: 'Upload a local file to Slock attachments. Prints the attachmentId for use with `message-send --attach`.',\n  domain: SLOCK_DOMAIN,\n  strategy: Strategy.COOKIE,\n  browser: true,\n  siteSession: 'persistent',\n  args: [\n    { name: 'file', positional: true, required: true, help: 'Local file path to upload (single file; max 50 MB)' },\n    { name: 'channel', positional: true, required: true, help: 'channelId UUID or #name — server requires the attachment be scoped to a channel' },\n    { name: 'server', help: 'Override active server slug' },\n  ],\n  columns: ['attachmentId', 'filename', 'mimeType', 'sizeBytes'],\n  func: async (page, kwargs) => {\n    const filePath = String(kwargs.file ?? '').trim();\n    if (!filePath) throw new ArgumentError('file path required');\n    const channel = String(kwargs.channel ?? '').trim();\n    if (!channel) throw new ArgumentError('channel required (UUID or #name); server rejects uploads without channelId');\n    const abs = path.resolve(filePath);\n    let stat;\n    try { stat = fs.statSync(abs); }\n    catch (e) { throw new ArgumentError(`file not readable: ${abs} (${e.message})`); }\n    if (!stat.isFile()) throw new ArgumentError(`not a regular file: ${abs}`);\n    if (stat.size === 0) throw new ArgumentError(`file is empty: ${abs}`);\n    if (stat.size > MAX_BYTES) {\n      throw new ArgumentError(`file is ${stat.size} bytes, exceeds server limit ${MAX_BYTES} (50 MiB). Split or compress before upload.`);\n    }\n\n    const buf = fs.readFileSync(abs);\n    const filename = path.basename(abs);\n    const b64 = buf.toString('base64');\n\n    await page.goto(SLOCK_HOME_URL);\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/slock/attachment-upload.js#L32-L68","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass the local file path as the first positional argument: `attachment-upload ./report.pdf #general`.","Check that the variable holding the path is actually set before invoking: `: \"${FILE_PATH:?FILE_PATH not set}\"`.","If the file is produced by a previous pipeline step, verify that step succeeded and wrote its output before running the upload."],"exampleFix":"// before (shell): unset var silently becomes empty argument\nattachment-upload \"$FILE_PATH\" \"$CHANNEL\"\n// after: fail fast if unset/empty\n: \"${FILE_PATH:?FILE_PATH not set}\"\nattachment-upload \"$FILE_PATH\" \"$CHANNEL\"","handlingStrategy":"validation","validationCode":"const filePath = String(process.argv[2] ?? '').trim();\nif (!filePath) {\n  throw new Error('file path required: pass the local file as the first argument');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await upload({ file: filePath, channel });\n} catch (e) {\n  if (e instanceof ArgumentError && e.message === 'file path required') {\n    console.error('Usage: attachment-upload <file> <channel>');\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["In shell scripts, guard interpolated paths with `${VAR:?msg}` so unset variables abort before the CLI runs.","Quote all path arguments to prevent empty expansion from word splitting.","Keep a fixed argument order: file first, channel second, for positional args."],"tags":["argument-error","missing-argument","cli","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}