{"record":{"id":"a2109b898b76b7c5","repo":"gleam-lang/gleam","slug":"non-utf-8-path-tests","errorCode":null,"errorMessage":"Non Utf-8 Path","messagePattern":"Non Utf-8 Path","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-cli/src/fs/tests.rs","lineNumber":37,"sourceCode":"    assert!(super::is_inside_git_work_tree(path).unwrap())\n}\n\n#[test]\nfn git_init_success() {\n    let tmp_dir = tempfile::tempdir().unwrap();\n    let path = Utf8Path::from_path(tmp_dir.path()).expect(\"Non Utf-8 Path\");\n    let git = path.join(\".git\");\n\n    assert!(!git.exists());\n    assert_eq!(super::git_init(path), Ok(()));\n    assert!(git.exists());\n}\n\n#[test]\nfn git_init_already_in_git() {\n    let tmp_dir = tempfile::tempdir().unwrap();\n    let git = Utf8Path::from_path(tmp_dir.path())\n        .expect(\"Non Utf-8 Path\")\n        .join(\".git\");\n    assert!(!git.exists());\n    assert_eq!(\n        super::git_init(Utf8Path::from_path(tmp_dir.path()).expect(\"Non Utf-8 Path\")),\n        Ok(())\n    );\n    assert!(git.exists());\n\n    let sub = Utf8Path::from_path(tmp_dir.path())\n        .expect(\"Non Utf-8 Path\")\n        .join(\"subproject\");\n    let git = sub.join(\".git\");\n    crate::fs::mkdir(&sub).unwrap();\n    assert!(!git.exists());\n    assert_eq!(super::git_init(&sub), Ok(()));\n    assert!(!git.exists());\n}\n","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/gleam-lang/gleam/blob/15b07c783065c92bb016b1b74ed0995a5259850f/compiler-cli/src/fs/tests.rs#L19-L55","documentation":"In the test `git_init_already_in_git`, `Utf8Path::from_path(tmp_dir.path()).expect(\"Non Utf-8 Path\")` panics if the temp directory path cannot be converted to a UTF-8 path. The conversion fails only when the OS temp path contains non-UTF-8 bytes.","triggerScenarios":"Running the test suite with TMPDIR (or the platform temp dir) set to a path containing non-UTF-8 bytes; the first expect at the `.git` join (compiler-cli/src/fs/tests.rs:37) panics before any assertion runs.","commonSituations":"CI machines or developer environments where the temp directory lives under a non-UTF-8 directory name (non-English locale setups, legacy-encoded usernames).","solutions":["Set TMPDIR to a UTF-8-safe directory when running tests: `TMPDIR=/tmp/utf8safe cargo test`.","Rename the temp/username directory to contain only UTF-8 characters.","Ignore/patch the test on non-UTF-8 filesystems, or make the helper return a Result instead of expecting."],"exampleFix":"// before\nlet git = Utf8Path::from_path(tmp_dir.path()).expect(\"Non Utf-8 Path\").join(\".git\");\n// after\nlet git = Utf8Path::from_path(tmp_dir.path())\n    .ok_or_else(|| anyhow!(\"temp dir path is not UTF-8\"))?\n    .join(\".git\");","handlingStrategy":"validation","validationCode":"if let Err(_) = std::str::from_utf8(tmp_dir.path().as_os_str().as_encoded_bytes()) {\n    eprintln!(\"skipping: TMPDIR is not UTF-8\");\n    return;\n}","typeGuard":"fn is_utf8_path(p: &std::path::Path) -> bool { p.to_str().is_some() }","tryCatchPattern":null,"preventionTips":["Always run test suites with TMPDIR set to a plain UTF-8 path","Standardize CI runners on UTF-8 locales (LC_ALL=C.UTF-8)","Avoid non-ASCII/legacy-encoded usernames and mount points on build machines","Prefer Result-returning path conversions over expect in test helpers"],"tags":["rust","tests","panic","encoding"],"backgroundTag":"internal-invariant-violation","analyzedSha":"15b07c783065c92bb016b1b74ed0995a5259850f","analyzedAt":"2026-09-14T11:14:59.388Z","contentChangedAt":"2026-09-14T11:14:59.388Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}