JuliusBrussee/caveman · error

usage: import --format

Error message

usage: ${invokedCommand("audit")} import --format <fmt> <file>

What it means

`auditImport` requires a file positional argument after options. `positionalAfterOptions` returns nothing when no positional file is present, so the CLI throws a usage error telling the exact expected form `caveman audit import --format <fmt> <file>`.

Solutions

  1. Append the file path as the final positional argument: `caveman audit import --format caveman-jsonl ./events.jsonl`.
  2. Run `caveman audit import` with no args to see usage and confirm argument order.
  3. Ensure the file path is quoted if it contains spaces.

Example fix

// before (shell)
caveman audit import --format caveman-jsonl
// error: usage: caveman audit import --format <fmt> <file>
// after (shell)
caveman audit import --format caveman-jsonl ./audit-events.jsonl
Defensive patterns

Strategy: validation

Validate before calling

// shell
[ $# -ge 1 ] && [ -f "$1" ] || { echo "usage: caveman audit import --format <fmt> <file>"; exit 1; }

Prevention

When it happens

Trigger: Running `caveman audit import --format caveman-jsonl` (or with no arguments at all) without supplying the input file path as the trailing positional argument.

Common situations: Copy-pasting a command and dropping the file argument; putting the file path before the options in an order the parser rejects; forgetting the file because the format flag was supplied.

Understand the failure class

Background: "no subcommand specified" and "... is required": CLI errors when a required argument is missing — this error's family across 13 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/381af2ce1fce3fd8. Report an issue: GitHub.

Appendix: source

Thrown at packages/cli/src/index.ts:17576

  const body = await post(`/api/v1/projects/${await projectId()}/keys`, { name: flagFrom(argv, "--name", "cli-key"), scopes: ["proxy:write", "sdk:write"] });
  print(body);
}

async function audit(argv: string[]) {
  if (argv[0] === "import") return auditImport(argv);
  if (argv[0] === "eval-import") return auditEvalImport(argv);
  if (argv[0] === "report") return get(`/api/v1/audits/${argv[1] ?? "aud_demo"}`).then(print);
  return post("/api/v1/audits", { last: flagFrom(argv, "--last", "7d") }).then(print);
}

// auditImport reads a telemetry export file and POSTs it to /api/v1/imports.
// Usage: caveman audit import --format <fmt> <file> [--field-map <json>]
// The org/project scope is resolved server-side from the auth token — never
// from the file (tenant-scoped rule).
async function auditImport(argv: string[]) {
  const format = flagFrom(argv, "--format", "caveman-jsonl");
  const file = positionalAfterOptions(argv.slice(1), new Set(["--format", "--field-map"]));
  if (!file) throw new Error(`usage: ${invokedCommand("audit")} import --format <fmt> <file>`);
  const data = await readFile(file);
  const cfg = await config();
  const headers: Record<string, string> = {
    authorization: `Bearer ${cfg.token}`,
    "content-type": "application/octet-stream",
    "x-cave-csrf": "cli"
  };
  const fieldMap = flagFrom(argv, "--field-map", "");
  if (fieldMap) headers["x-cave-field-map"] = fieldMap;
  const response = await fetch(`${cfg.baseURL}/api/v1/imports?format=${encodeURIComponent(format)}`, {
    method: "POST",
    headers,
    body: data
  });
  print(await response.json());
}

// auditEvalImport turns newline-delimited, source-neutral eval records into one

View on GitHub (pinned to 3ee70a1026)