{"record":{"id":"b856114aa5a0aea6","repo":"dbt-labs/dbt-core","slug":"clap-requires-environment-unless-sdist-out","errorCode":null,"errorMessage":"clap requires --environment unless --sdist-out","messagePattern":"clap requires --environment unless --sdist-out","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-ci/src/publish.rs","lineNumber":166,"sourceCode":"            return ExitCode::from(2);\n        }\n    };\n\n    // Build-only mode: assemble the sdist into `--sdist-out` and stop. The\n    // release pipeline stages it to S3/CDN itself, so no upload target is needed.\n    if let Some(out_dir) = &args.sdist_out {\n        return match rt.block_on(build_only_sdist(&args, &spec, out_dir)) {\n            Ok(()) => ExitCode::SUCCESS,\n            Err(e) => {\n                eprintln!(\"error: {e:#}\");\n                ExitCode::from(2)\n            }\n        };\n    }\n\n    let target = match PublishTarget::from_env(\n        args.environment\n            .expect(\"clap requires --environment unless --sdist-out\"),\n    ) {\n        Ok(t) => t,\n        Err(e) => {\n            eprintln!(\"error: {e:#}\");\n            return ExitCode::from(64);\n        }\n    };\n    match rt.block_on(run_publish(&args, &spec, target)) {\n        Ok(()) => ExitCode::SUCCESS,\n        Err(e) => {\n            eprintln!(\"error: {e:#}\");\n            ExitCode::from(2)\n        }\n    }\n}\n\n/// Builds the download-at-install sdist into `out_dir` without uploading it.\nasync fn build_only_sdist(","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-ci/src/publish.rs#L148-L184","documentation":"Invariant expect in the publish CLI's execute: clap's `requires` rule guarantees that when no --sdist-out is given, --environment was provided, so unwrapping args.environment must succeed. Fires only if the clap argument definition and this code drift apart — an internal bug, not a user input error.","triggerScenarios":"Thrown at crates/dbt-ci/src/publish.rs:166 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Keep the clap `requires` attributes in sync with the expects in execute","Add a CLI parsing test covering the --environment/--sdist-out matrix","Report as an internal bug in dbt-ci publish"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}