{"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":null,"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/5bb508f59481c1a02d5c7ff8568b9ffd8a763eef/crates/ty_completion_eval/src/main.rs#L141-L177","documentation":"After creating a temporary directory, the evaluator converts its path to a `SystemPath`, which requires valid UTF-8. If the OS temp path (e.g. TMPDIR-derived) is not valid UTF-8, this error aborts the run.","triggerScenarios":"Running ty_completion_eval with TMPDIR set to a non-UTF-8 path, or systems whose default temp directory contains invalid UTF-8 bytes.","commonSituations":"Custom TMPDIR exports with byte-level names; non-UTF-8 container mount points used for /tmp.","solutions":["Set TMPDIR to a valid UTF-8 path (e.g. `TMPDIR=/tmp/evaltmp`) and rerun","Rename or recreate the offending temp directory with a UTF-8-safe name"],"exampleFix":"# before\nTMPDIR=/tmp/w$(printf '\\xff') cargo run -p ty_completion_eval -- all\n// after\nTMPDIR=/tmp/evaltmp cargo run -p ty_completion_eval -- all","handlingStrategy":"validation","validationCode":"import os, sys\ntmp = os.environ.get('TMPDIR', '/tmp')\ntry:\n    tmp.encode('utf-8')\nexcept UnicodeEncodeError:\n    sys.exit(f\"TMPDIR {tmp!r} is not UTF-8; set TMPDIR to a UTF-8 path\")","typeGuard":null,"tryCatchPattern":"match eval_main() {\n    Err(e) if e.to_string().contains(\"Temporary directory path is not valid UTF-8\") => {\n        std::env::set_var(\"TMPDIR\", \"/tmp/utf8safe\");\n        // retry once\n    }\n    result => result,\n}","preventionTips":["Export TMPDIR with ASCII-only values in CI and dev shells","Avoid mounting /tmp from non-UTF-8 filesystems","Validate TMPDIR encoding in wrapper scripts before running the evaluator"],"tags":["unicode","temp-directory","environment"],"backgroundTag":"non-unicode-path","analyzedSha":"5bb508f59481c1a02d5c7ff8568b9ffd8a763eef","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}