DioxusLabs/dioxus · error
failed to parse toml at {}: {}
Error message
failed to parse toml at {}: {} What it means
As a post-creation step, dx formats the freshly generated Cargo.toml and Dioxus.toml by parsing them with toml_edit::DocumentMut and rewriting. If either file fails to parse as TOML, the command aborts with this error including the file path and the parser's message. Since both files were just generated, a parse failure almost always means a broken/custom template or concurrent modification.
Source
Thrown at packages/cli/src/cli/create.rs:198
// 2. Run `cargo fmt` on the new project.
let mut cmd = Command::new("cargo");
let cmd = cmd.arg("fmt").current_dir(path);
let output = cmd.output().expect("failed to execute process");
if !output.status.success() {
tracing::error!(dx_src = ?TraceSrc::Dev, "cargo fmt failed");
tracing::error!(dx_src = ?TraceSrc::Build, "stdout: {}", String::from_utf8_lossy(&output.stdout));
tracing::error!(dx_src = ?TraceSrc::Build, "stderr: {}", String::from_utf8_lossy(&output.stderr));
}
// 3. Format the `Cargo.toml` and `Dioxus.toml` files.
let toml_paths = [path.join("Cargo.toml"), path.join("Dioxus.toml")];
for toml_path in &toml_paths {
let Ok(toml) = std::fs::read_to_string(toml_path) else {
continue;
};
let mut toml = toml.parse::<toml_edit::DocumentMut>().map_err(|e| {
anyhow::anyhow!("failed to parse toml at {}: {}", toml_path.display(), e)
})?;
toml.as_table_mut().fmt();
let as_string = toml.to_string();
let new_string = remove_triple_newlines(&as_string);
let mut file = std::fs::File::create(toml_path)?;
file.write_all(new_string.as_bytes())?;
}
// 4. Remove any triple newlines from the readme.
let readme_path = path.join("README.md");
let readme = std::fs::read_to_string(&readme_path)?;
let new_readme = remove_triple_newlines(&readme);
let mut file = std::fs::File::create(readme_path)?;
file.write_all(new_readme.as_bytes())?;
// 5. Run git initView on GitHub (pinned to 393d190a80)
Solutions
- Open the file named in the error and fix the TOML syntax at the position the parser reports
- Re-run dx create without the custom template to confirm the default template is healthy
- Update dx (check dx --version) if a stale CLI ships broken templates
- If a specific custom template always fails, fix or report it upstream
Defensive patterns
Strategy: validation
Validate before calling
# Sanity-parse the generated TOML right after dx create python3 -c 'import tomllib,sys; tomllib.load(open(sys.argv[1],"rb"))' path/to/Cargo.toml
Prevention
- Prefer stock templates unless a custom one is known-good
- Keep dx updated so scaffold templates stay valid
- Disable format-on-save for files under a freshly scaffolded directory until dx finishes
When it happens
Trigger: dx create with a custom template that emits malformed TOML, or an external tool (editor autoformat, file watcher, pre-commit hook) mutating Cargo.toml/Dioxus.toml between generation and the formatting step.
Common situations: Using a community template with invalid TOML; an old dx version shipping a broken default template; aggressive editor format-on-save racing the scaffold.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Couldn't retrieve cargo metadata: {:?}
- Syntax Error in line {line} column {column}: {err}
- Package type '{invalid:?}' is not supported for bundle forma
- 1 issue found.
- Component '{}' not found in registry
AI-assisted analysis of DioxusLabs/dioxus@393d190a80 (2026-08-16).
Data as JSON: /api/errors/4797b94e364ee152.
Report an issue: GitHub.