{"id":"303faacfe9bb1c75","repo":"rust-lang/cargo","slug":"unexpected-btype-bracket-literal-in-build-bu","errorCode":null,"errorMessage":"unexpected {btype} bracket `{literal}` in build.build-dir path `{raw_template}`","messagePattern":"unexpected (.+?) bracket `(.+?)` in build\\.build-dir path `(.+?)`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/context/mod.rs","lineNumber":820,"sourceCode":"                    variable,\n                    raw_template,\n                } => {\n                    let mut suggestion = closest_msg(&variable, template_variables.iter(), |key| key, \"template variable\");\n                    if suggestion == \"\" {\n                        let variables = template_variables.iter().map(|v| format!(\"`{{{v}}}`\")).join(\", \");\n                        suggestion = format!(\"\\n\\nhelp: available template variables are {variables}\");\n                    }\n                    anyhow!(\n                            \"unexpected variable `{variable}` in build.build-dir path `{raw_template}`{suggestion}\"\n                        )\n                }\n                path::ResolveTemplateError::UnexpectedBracket { bracket_type, raw_template } => {\n                    let (btype, literal) = match bracket_type {\n                        path::BracketType::Opening => (\"opening\", \"{\"),\n                        path::BracketType::Closing => (\"closing\", \"}\"),\n                    };\n\n                    anyhow!(\n                            \"unexpected {btype} bracket `{literal}` in build.build-dir path `{raw_template}`\"\n                        )\n                }\n            })?;\n\n        // Check if the target directory is set to an empty string in the config.toml file.\n        if val.raw_value().is_empty() {\n            bail!(\n                \"the build directory is set to an empty string in {}\",\n                val.value().definition\n            )\n        }\n\n        Ok(Filesystem::new(path))\n    }\n\n    /// Get a configuration value by key.\n    ///","sourceCodeStart":802,"sourceCodeEnd":838,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/context/mod.rs#L802-L838","documentation":"While resolving `build.build-dir`, if resolve_templated_path encounters an unbalanced brace (an opening `{` with no closing `}` or a stray `}`), it returns UnexpectedBracket and Cargo bails 'unexpected <opening|closing> bracket `{`|`}` in build.build-dir path `<template>`' (mod.rs:814-823). The bracket_type maps to 'opening'/'closing' with the literal brace character.","triggerScenarios":"A build-dir value with a stray or unmatched brace, e.g. `build-dir = \"/x/{workspace-root}` (missing close) or a template that opens a variable but never closes it.","commonSituations":"Hand-editing config.toml and dropping a `}`; copy-paste truncation; intending a literal brace but using the template syntax.","solutions":["Balance every `{` with a `}` in the build-dir template.","Remove unintended braces so the path is a plain literal.","Re-read the message: it shows the exact raw template that failed."],"exampleFix":"# before (.cargo/config.toml)\n[build]\nbuild-dir = \"/cache/{workspace-path-hash/target\"  # missing }\n# after\n[build]\nbuild-dir = \"/cache/{workspace-path-hash}/target\"","handlingStrategy":"validation","validationCode":"# Check build-dir braces are balanced:\npython3 - <<'EOF'\nimport tomllib\ntry:\n    d = tomllib.load(open('.cargo/config.toml','rb'))\nexcept FileNotFoundError: raise SystemExit(0)\nbd = d.get('build',{}).get('build-dir')\nif bd:\n    assert bd.count('{') == bd.count('}'), 'unbalanced braces in build-dir'\nEOF","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Balance every { with a } in build-dir templates.","Run a TOML lint in CI to catch malformed templates early.","Avoid literal braces in paths unless documented as escapable."],"tags":["config","build-dir","template","syntax","path"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}