{"record":{"id":"6513496908f08867","repo":"swc-project/swc","slug":"failed-to-read-cargo-manifest-dir-err","errorCode":null,"errorMessage":"failed to read `CARGO_MANIFEST_DIR`: {err}","messagePattern":"failed to read `CARGO_MANIFEST_DIR`: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/testing/src/paths.rs","lineNumber":12,"sourceCode":"use std::{env, path::PathBuf, sync::Arc};\n\nuse once_cell::sync::Lazy;\n\npub fn manifest_dir() -> PathBuf {\n    env::var(\"CARGO_MANIFEST_DIR\")\n        .map(PathBuf::from)\n        .map(|p| {\n            p.canonicalize()\n                .expect(\"failed to canonicalize `CARGO_MANIFEST_DIR`\")\n        })\n        .unwrap_or_else(|err| panic!(\"failed to read `CARGO_MANIFEST_DIR`: {err}\"))\n}\n\n/// This directory is per-crate.\npub fn test_results_dir() -> Arc<PathBuf> {\n    fn detect() -> PathBuf {\n        manifest_dir().join(\"target\").join(\"swc-test-results\")\n    }\n\n    static DIR: Lazy<Arc<PathBuf>> = Lazy::new(|| Arc::new(detect()));\n\n    DIR.clone()\n}\n","sourceCodeStart":1,"sourceCodeEnd":25,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/testing/src/paths.rs#L1-L25","documentation":"Raised in `manifest_dir` (crates/testing/src/paths.rs:12). The function reads the CARGO_MANIFEST_DIR environment variable to locate the crate root; the panic fires when the variable is unset (env::var returns Err), i.e. the code is running outside a cargo-driven build/test context where cargo normally injects this variable. The missing environment variable is the input at fault.","triggerScenarios":"Thrown at crates/testing/src/paths.rs:12 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Run the code through cargo (cargo test / cargo run) so CARGO_MANIFEST_DIR is set","Set CARGO_MANIFEST_DIR manually when invoking the test binary directly","Derive the manifest path from a build-script-generated env! constant instead of runtime env::var"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}