gitbutlerapp/gitbutler · error

Unknown argument

Error message

Unknown argument: {other}

What it means

`parse_args` in the but-ts CLI rejects any command-line argument it does not recognize with `bail!("Unknown argument: {other}")`. The generator only accepts `--output`, `--source-crates`, and `--help`; anything else is a hard failure before generation starts.

Solutions

  1. Run `but-ts --help` to list the accepted flags (`--output <path> [--source-crates <crate1,crate2,...>])`.
  2. Fix the typo in the flag name (e.g. `--out` → `--output`).
  3. Remove any positional/extra arguments that the current but-ts version does not support.

Example fix

// before
but-ts --out-dir ../sdk/src/types
// after
but-ts --output ../sdk/src/types.ts --source-crates but-core,but-workspace
Defensive patterns

Strategy: validation

Validate before calling

const ALLOWED: &[&str] = &["--output", "--source-crates", "--help"];
for a in std::env::args().skip(1) {
    assert!(ALLOWED.iter().any(|f| a.starts_with(f)), "unsupported flag: {a}");
}

Prevention

When it happens

Trigger: Running `but-ts` with a mistyped or unsupported flag, e.g. `but-ts --out path` or `but-ts --output=path extra-flag`, or passing a positional argument the parser does not handle.

Common situations: Copy-pasting invocation examples from older docs or scripts; typo in `--output`/`--source-crates`; passing flags meant for other codegen tools (e.g. `--out-dir`).

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/31fb5f2d3e7d8793. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-ts/src/main.rs:544

            "--source-crates" => {
                let val = args.next().ok_or_else(|| {
                    anyhow::anyhow!(
                        "--source-crates requires a comma-separated list of crate prefixes"
                    )
                })?;
                source_crates.extend(
                    val.split(',')
                        .map(|s| s.trim())
                        .filter(|s| !s.is_empty())
                        .map(str::to_string),
                );
            }
            "--help" | "-h" => {
                eprintln!("Usage: but-ts --output <path> [--source-crates <crate1,crate2,...>]");
                std::process::exit(0);
            }
            other => {
                anyhow::bail!("Unknown argument: {other}");
            }
        }
    }
    Ok(Args {
        output: output.ok_or_else(|| anyhow::anyhow!("--output is required"))?,
        source_crates,
    })
}

/// Returns true if the property schema is nullable (its TS type includes `| null`).
fn is_nullable(schema: &serde_json::Value) -> bool {
    let Some(obj) = schema.as_object() else {
        return false;
    };
    // anyOf: [..., { "type": "null" }]  — used for nullable struct/enum types
    if let Some(arr) = obj.get("anyOf").and_then(|v| v.as_array()) {
        return arr.iter().any(|s| {
            s.as_object()

View on GitHub (pinned to 58e5313667)