{"record":{"id":"9b86c6d3887bce63","repo":"stalwartlabs/stalwart","slug":"failed-to-read-yaml-path","errorCode":null,"errorMessage":"Failed to read {yaml_path:?}","messagePattern":"Failed to read (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/common/build.rs","lineNumber":15,"sourceCode":"use std::collections::{HashMap, HashSet};\nuse std::env;\nuse std::fs;\nuse std::path::Path;\n\nfn main() {\n    let out_dir = env::var(\"OUT_DIR\").unwrap();\n    let dest_path = Path::new(&out_dir).join(\"locales.rs\");\n\n    // Read the YAML file\n    let manifest_dir = env::var(\"CARGO_MANIFEST_DIR\").unwrap();\n    let repo_root = Path::new(&manifest_dir).parent().unwrap().parent().unwrap();\n    let yaml_path = repo_root.join(\"resources/locales/i18n.yml\");\n    let yaml_content =\n        fs::read_to_string(&yaml_path).unwrap_or_else(|_| panic!(\"Failed to read {yaml_path:?}\"));\n\n    let locales = parse_yaml(&yaml_content);\n\n    let generated_code = generate_locale_code(&locales);\n\n    fs::write(&dest_path, generated_code).expect(\"Failed to write generated locales.\");\n\n    println!(\"cargo:rerun-if-changed={}\", yaml_path.display());\n}\n\nfn parse_yaml(content: &str) -> HashMap<String, HashMap<String, String>> {\n    let mut result: HashMap<String, HashMap<String, String>> = HashMap::new();\n    let mut current_key = None;\n\n    for line in content.lines() {\n        if let Some((key, value)) = line.split_once(':') {\n            let is_translation = key\n                .as_bytes()","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/stalwartlabs/stalwart/blob/e96200385781a6a9995a8b839ac27d6c75a983ee/crates/common/build.rs#L1-L33","documentation":"This panic is raised by the build script of the `common` crate when it cannot read `resources/locales/i18n.yml`, the YAML file from which all localization strings are code-generated into `locales.rs`. Without this file the build cannot produce the locale constants, so the script aborts compilation immediately with the resolved absolute path in the message. It is a fail-fast guard rather than a recoverable error.","triggerScenarios":"Running `cargo build` when the repo-root-relative path `<repo>/resources/locales/i18n.yml` does not exist or is unreadable. The path is derived from CARGO_MANIFEST_DIR by going up two parent directories, so building a copy of the crate that is no longer two levels below the repo root, or a checkout with sparse/filtered resources, will also fail.","commonSituations":"Incomplete git clones (sparse checkout, submodule-less checkout, download of a single crate without resources), packaging the crate into a vendored/offline directory layout that breaks the two-level parent assumption, deleting or renaming the i18n.yml during refactoring, or filesystem permission issues on the resources directory.","solutions":["Verify `resources/locales/i18n.yml` exists at the repo root and restore it (e.g. `git checkout -- resources/locales/i18n.yml`).","Build from the repository root layout so CARGO_MANIFEST_DIR is exactly two levels below the repo root; do not relocate the crate directory.","Check that your sparse-checkout / CI artifact includes the `resources/` directory.","Fix filesystem permissions on the resources directory if read access is denied."],"exampleFix":"// If i18n.yml was deleted:\n// $ git restore resources/locales/i18n.yml\n// If building from a relocated crate, restore the layout:\n// before: vendor/common/   (repo root detection fails)\n// after:  <repo>/crates/common/  with <repo>/resources/locales/i18n.yml present","handlingStrategy":"validation","validationCode":"use std::path::Path;\nlet yaml = Path::new(env!(\"CARGO_MANIFEST_DIR\")).ancestors().nth(2).unwrap().join(\"resources/locales/i18n.yml\");\nassert!(yaml.is_file(), \"missing locale manifest: {}\", yaml.display());","typeGuard":null,"tryCatchPattern":"// build scripts cannot catch panics usefully; validate before reading:\nlet content = fs::read_to_string(&yaml_path).unwrap_or_else(|e|\n    panic!(\"Failed to read {yaml_path:?}: {e}\"));","preventionTips":["Keep the crate in its canonical crates/<name> layout so the two-level parent walk finds the repo root.","Ensure CI checkouts include the resources/ directory (avoid sparse checkout of it).","Add a repo lint/test that asserts resources/locales/i18n.yml exists."],"tags":["build-script","file-not-found","i18n","rust"],"backgroundTag":"config-file-not-found","analyzedSha":"e96200385781a6a9995a8b839ac27d6c75a983ee","analyzedAt":"2026-09-06T22:07:17.982Z","contentChangedAt":"2026-09-06T22:07:17.982Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}