{"record":{"id":"e4598317bc2d5406","repo":"BoundaryML/baml","slug":"file-and-project-are-mutually-exclusive-file-already-names","errorCode":null,"errorMessage":"`--file` and `--project` are mutually exclusive; `--file` already names the single source to load.","messagePattern":"`--file` and `--project` are mutually exclusive; `--file` already names the single source to load\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/project_load.rs","lineNumber":26,"sourceCode":"\nuse crate::reporter::Reporter;\n\n/// The source location shape shared by `run`, `pack`, and `playground`.\n#[derive(Debug, Clone, PartialEq, Eq)]\npub(crate) enum SourceLocation {\n    /// A resolved BAML project root discovered by walking up from `from` or cwd.\n    Project { root: PathBuf, files: Vec<PathBuf> },\n    /// A hermetic single-file source selected through `--file`.\n    StandaloneFile { file: PathBuf, root: PathBuf },\n}\n\n/// `--file` and `--project` both name a source location.\npub(crate) fn validate_file_project_flags(\n    file: Option<&Path>,\n    project: Option<&Path>,\n) -> Result<()> {\n    if file.is_some() && project.is_some() {\n        anyhow::bail!(\n            \"`--file` and `--project` are mutually exclusive; `--file` already names \\\n             the single source to load.\"\n        );\n    }\n    Ok(())\n}\n\n/// Resolve the CLI source location exactly like `baml run` project/file mode.\npub(crate) fn resolve_source_location(\n    from: Option<&Path>,\n    file: Option<&Path>,\n    reporter: Option<&Reporter>,\n) -> Result<SourceLocation> {\n    validate_file_project_flags(file, from)?;\n\n    if let Some(file) = file {\n        let canonical = resolve_standalone_file(file)?;\n        let root = canonical","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/project_load.rs#L8-L44","documentation":"validate_file_project_flags enforces that `--file` and `--project` are mutually exclusive: both select a source location, and `--file` already means 'load exactly this one file'. Passing both is ambiguous, so the CLI refuses the invocation up front.","triggerScenarios":"Any CLI command (baml dev/test/validate via validate_flags, resolve_source_location, run_with_reporter, or test_run_allows_file_with_omitted_from) invoked with both a --file path and a --project path set at the same time.","commonSituations":"Shell scripts accumulating flags where --project is always passed and --file is appended conditionally; copying an example command line and adding --file; an alias wrapping the command with --project baked in.","solutions":["Remove --project and keep only --file to compile/test a single standalone file.","Remove --file and keep only --project to load the whole project.","If a wrapper script adds --project conditionally, gate it so it's omitted whenever --file is supplied."],"exampleFix":"// before\nbaml dev --project ./baml_src --file ./baml_src/main.baml\n\n// after\nbaml dev --file ./baml_src/main.baml","handlingStrategy":"validation","validationCode":"#!/usr/bin/env bash\nEXTRA=()\n[ -n \"$FILE\" ] && EXTRA+=(--file \"$FILE\")\n[ -z \"$FILE\" ] && [ -n \"$PROJECT\" ] && EXTRA+=(--project \"$PROJECT\")\nbaml dev \"${EXTRA[@]}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never hardcode --project in wrapper scripts that also accept --file.","Decide per invocation: single file → --file only; whole project → --project only.","Add a shell alias guard that errors when both variables are set."],"tags":["cli","baml","flags","argument-conflict"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}