{"record":{"id":"80980de906265a74","repo":"astral-sh/ruff","slug":"temporary-directory-path-is-not-valid-utf-8","errorCode":null,"errorMessage":"Temporary directory path is not valid UTF-8: {}","messagePattern":"Temporary directory path is not valid UTF-8: (.+?)","errorType":"console","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/ty_completion_eval/src/main.rs","lineNumber":159,"sourceCode":"    let truth = cwd.join(\"crates\").join(\"ty_completion_eval\").join(\"truth\");\n    anyhow::ensure!(\n        truth.as_std_path().exists(),\n        \"{truth} does not exist: ty's completion evaluation must be run from the root \\\n         of the ruff repository\",\n        truth = truth.as_std_path().display(),\n    );\n\n    // The temporary directory at which we copy our truth\n    // data to. We do this because we can't use the truth\n    // data as-is with its `<CURSOR>` annotations (and perhaps\n    // any other future annotations we add).\n    let mut tmp_eval_dir = tempfile::Builder::new()\n        .prefix(\"ty-completion-eval-\")\n        .tempdir()\n        .context(\"Failed to create temporary directory\")?;\n    let tmp_eval_path = SystemPath::from_std_path(tmp_eval_dir.path())\n        .ok_or_else(|| {\n            anyhow::anyhow!(\n                \"Temporary directory path is not valid UTF-8: {}\",\n                tmp_eval_dir.path().display()\n            )\n        })?\n        .to_path_buf();\n\n    let sources = TaskSource::all(&truth)?;\n    match args.command {\n        Command::ShowOne(ref cmd) => {\n            tmp_eval_dir.disable_cleanup(cmd.keep_tmp_dir);\n\n            let Some(source) = sources\n                .iter()\n                .find(|source| cmd.matches_source_task(source))\n            else {\n                anyhow::bail!(\"could not find task named `{}`\", cmd.task_name);\n            };\n            let tasks = source.to_tasks(&tmp_eval_path)?;","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/astral-sh/ruff/blob/672bb4edf04c84f8b0753346359daee4057158f2/crates/ty_completion_eval/src/main.rs#L141-L177","documentation":"After creating its scratch directory via `tempfile::Builder`, the harness converts the temp path to a `SystemPath`; `SystemPath::from_std_path` returns None when the path is not valid UTF-8 (it does not lossily convert), so the run aborts. In practice this means TMPDIR — or the OS default temp location — points into a non-Unicode path.","triggerScenarios":"`TMPDIR` exported to a path containing invalid UTF-8 bytes; containers/sandboxes whose temp mount or env carries byte-mangled paths; the message echoes the offending path via `display()`.","commonSituations":"CI containers with odd TMPDIR values; wrappers that derive TMPDIR from a non-UTF-8 workspace path; test harnesses chaining temp dirs from other tools.","solutions":["Point TMPDIR at a clean location: `export TMPDIR=/tmp` and re-run","Fix the container image or wrapper script that sets TMPDIR to a non-UTF-8 path","Verify with a UTF-8 round-trip check before invoking the harness"],"exampleFix":"# before\nTMPDIR=$'/tmp/bad\\xff' cargo run -p ty_completion_eval -- all\n# after\nexport TMPDIR=/tmp && cargo run -p ty_completion_eval -- all","handlingStrategy":"validation","validationCode":"python3 -c 'import os,sys; os.environ.get(\"TMPDIR\", \"/tmp\").encode(\"utf-8\")' 2>/dev/null \\\n  || { echo \"TMPDIR is not valid UTF-8\" >&2; exit 2; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep TMPDIR on a clean Unicode path (e.g. /tmp)","Audit container images and wrappers that set TMPDIR from workspace paths","Set TMPDIR explicitly in CI jobs that run the eval harness"],"tags":["unicode","tempfile","environment","evaluation"],"backgroundTag":null,"analyzedSha":"672bb4edf04c84f8b0753346359daee4057158f2","analyzedAt":"2026-08-16T08:54:05.464Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}