{"record":{"id":"8d75507f591a1a87","repo":"AlexsJones/llmfit","slug":"cargo-manifest-dir","errorCode":null,"errorMessage":"CARGO_MANIFEST_DIR","messagePattern":"CARGO_MANIFEST_DIR","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"llmfit-tui/build.rs","lineNumber":8,"sourceCode":"use std::env;\nuse std::fs;\nuse std::path::{Path, PathBuf};\n\nfn main() {\n    println!(\"cargo:rerun-if-changed=build.rs\");\n\n    let manifest_dir = PathBuf::from(env::var(\"CARGO_MANIFEST_DIR\").expect(\"CARGO_MANIFEST_DIR\"));\n    let dist_dir = manifest_dir.join(\"..\").join(\"llmfit-web\").join(\"dist\");\n    println!(\"cargo:rerun-if-changed={}\", dist_dir.display());\n\n    let out_dir = PathBuf::from(env::var(\"OUT_DIR\").expect(\"OUT_DIR\"));\n    let out_file = out_dir.join(\"web_assets.rs\");\n\n    let generated = if dist_dir.exists() {\n        let mut files = Vec::new();\n        collect_files(&dist_dir, &mut files);\n        files.sort();\n        for file in &files {\n            println!(\"cargo:rerun-if-changed={}\", file.display());\n        }\n        generate_assets_from_dist(&dist_dir, &files)\n    } else {\n        println!(\n            \"cargo:warning=llmfit-web/dist not found. Falling back to placeholder embedded dashboard. Run `npm ci && npm run build` in llmfit-web.\"\n        );","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/AlexsJones/llmfit/blob/acc7e40c3a0afbd36510a92f2f8f3d5177cfc0fe/llmfit-tui/build.rs#L1-L26","documentation":"llmfit-tui/build.rs reads CARGO_MANIFEST_DIR to locate ../llmfit-web/dist and emit rerun-if-changed directives. Cargo always defines this variable when it compiles a build script, so the .expect can only fail when build.rs is executed outside Cargo (e.g. directly with rustc, or by a tool that mimics cargo poorly). It is an environment-contract assertion, not a normal failure mode.","triggerScenarios":"Running `rustc build.rs` manually to debug the build script; invoking build.rs from an IDE task or script that does not set the cargo-provided environment; a nonstandard build wrapper that strips env.","commonSituations":"Developers experimenting with the build script in isolation; external tooling (Bazel-ish wrappers, codegen scripts) executing build.rs without the cargo contract.","solutions":["Run the build through cargo: `cargo build -p llmfit` (or `cargo check`) so CARGO_MANIFEST_DIR, OUT_DIR, and friends are set","If you must execute build.rs standalone, export CARGO_MANIFEST_DIR=/path/to/llmfit-tui and OUT_DIR to a temp dir first","Prefer `cargo build -vv` to debug build-script behavior rather than running it outside cargo"],"exampleFix":"# before\nrustc llmfit-tui/build.rs && ./a.out  # panics: CARGO_MANIFEST_DIR\n\n# after\ncargo check -p llmfit  # cargo sets CARGO_MANIFEST_DIR/OUT_DIR","handlingStrategy":"validation","validationCode":"// Only relevant if executing build.rs outside cargo:\nstd::env::var(\"CARGO_MANIFEST_DIR\")\n    .expect(\"run me via `cargo build`, or export CARGO_MANIFEST_DIR manually\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always drive build scripts through cargo so the env contract holds","Use `cargo build -vv` to inspect build-script behavior instead of executing it directly","If a wrapper must run build.rs, replicate the full cargo env (CARGO_MANIFEST_DIR, OUT_DIR)"],"tags":["rust","build-script","cargo","env-var","panic"],"backgroundTag":"missing-env-var","analyzedSha":"acc7e40c3a0afbd36510a92f2f8f3d5177cfc0fe","analyzedAt":"2026-08-17T10:35:29.658Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}