{"record":{"id":"9af5f4b7657587de","repo":"AlexsJones/llmfit","slug":"out-dir","errorCode":null,"errorMessage":"OUT_DIR","messagePattern":"OUT_DIR","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"llmfit-tui/build.rs","lineNumber":12,"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        );\n        generate_fallback_assets()\n    };\n\n    fs::write(&out_file, generated).expect(\"failed to write generated web_assets.rs\");","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/AlexsJones/llmfit/blob/acc7e40c3a0afbd36510a92f2f8f3d5177cfc0fe/llmfit-tui/build.rs#L1-L30","documentation":"The same build.rs reads OUT_DIR (the scratch directory cargo creates per compiled crate) to know where to write the generated web_assets.rs that embeds the dashboard. Cargo guarantees OUT_DIR for build script execution, so this .expect, like the CARGO_MANIFEST_DIR one, only fires when build.rs runs outside the cargo build environment.","triggerScenarios":"Directly invoking the compiled build script (`./libllmfit_build-script.out`) without env; a debugging harness that runs build.rs with a partially copied environment; cargo-external integration that forgets OUT_DIR.","commonSituations":"Build-script debugging sessions; custom build pipelines that try to pre-generate web_assets.rs by hand.","solutions":["Build via cargo: `cargo build -p llmfit` — OUT_DIR is provided automatically","For manual runs, set both CARGO_MANIFEST_DIR and OUT_DIR to writable directories (e.g. under /tmp) before executing the script","If you need the generated file for inspection, look under target/debug/build/llmfit-*/out/web_assets.rs after a cargo build instead"],"exampleFix":"# before\n./target/debug/build/llmfit-*/build-script-main  # panics: OUT_DIR\n\n# after\ncargo build -p llmfit\ncat target/debug/build/llmfit-*/out/web_assets.rs","handlingStrategy":"validation","validationCode":"// Only relevant if executing build.rs outside cargo:\nlet out_dir = std::env::var(\"OUT_DIR\")\n    .expect(\"run me via `cargo build`, or export OUT_DIR to a writable dir\");\nassert!(std::path::Path::new(&out_dir).is_dir(), \"OUT_DIR must exist and be writable\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never execute the compiled build script manually without the cargo environment","Inspect generated assets under target/debug/build/llmfit-*/out/ after a normal cargo build","Keep wrappers that invoke build.rs from re-implementing cargo's env half-way"],"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"}