flxzt/rnote · error
Failed to parse `type` attribute of XoppBackground with…
Error message
Failed to parse `type` attribute of XoppBackground with node id {:?}, is not a valid value What it means
This error is thrown while loading the `<background>` XML element of a Xournal++ (.xopp) file: the `type` attribute held a value that rnote does not recognize. The parser matches the attribute against a fixed set of known background types (e.g. "plain", "lined", "pixmap", "pdf") and falls into the `_` catch-all arm when none match, aborting the file load.
Solutions
- Open the .xopp file in Xournal++ itself and re-save it so the background uses a standard type rnote supports (plain, lined, ruled, graph, pixmap, pdf).
- Inspect the `<background type="...">` element in the file (unzip/edit XML) and correct or remove the unknown type value.
- Re-export the file from Xournal++ to the latest stable .xopp format and retry the import.
- If the type is legitimately new in a newer Xournal++ release, add it to the match in XoppBackground::load_from_xml and map it to an rnote background type.
Example fix
// before (file XML) <background type="gridd" style="blue:1:10:10" /> // after (file XML) <background type="graph" style="blue:1:10:10" />
Defensive patterns
Strategy: validation
Validate before calling
const KNOWN_BG_TYPES: [&str; 5] = ["plain", "lined", "ruled", "graph", "pixmap"];
fn background_type_supported(doc: &str) -> bool {
doc.contains("<background") && doc.split("type=\"").nth(1)
.map(|rest| KNOWN_BG_TYPES.iter().any(|t| rest.starts_with(t)))
.unwrap_or(true) // pdf handled separately
} Type guard
fn is_valid_bg_type(v: &str) -> bool {
matches!(v, "plain" | "lined" | "ruled" | "graph" | "pixmap" | "pdf")
} Try / catch
// pre-validate the file before import
if !is_valid_bg_type(extract_background_type(&xopp_xml)) {
eprintln!("Unsupported Xournal++ background type; re-save via Xournal++ first");
} else {
match rnote_import(&path) {
Err(e) => eprintln!("import failed: {e:#}"),
Ok(doc) => { /* use doc */ }
}
} Prevention
- Only import .xopp files saved by a Xournal++ version matching what rnote's importer targets
- Never hand-edit xopp XML background types; re-save via Xournal++ instead
- Sanity-check imported files by opening them in Xournal++ before import
- Handle the failure at import level so one bad file doesn't abort a batch
When it happens
Trigger: Calling XoppBackground::load_from_xml (via xopp file import) on a `<background type="...">` element whose type attribute is an unknown/unexpected string, e.g. an old or newer Xournal++ format version introducing a background type rnote's importer does not support, a hand-edited file with a typo like type="gridd", or a corrupted file where the attribute value was mangled.
Common situations: Importing .xopp files saved by a different Xournal++ version than the formats rnote's importer targets; hand-edited or template-generated xopp files with nonstandard background types; locale/corruption issues changing the attribute text.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to parse `tool` attribute in XoppStroke with node id
- failed to parse `color` attribute in XoppStroke with node id
- failed to parse `width` attribute in XoppStroke with node id
- failed to parse `font` attribute in XoppText with node id
- failed to parse `size` attribute in XoppText with node id
AI-assisted analysis of flxzt/rnote@bbc5354502 (2026-09-08).
Data as JSON: /api/errors/26b0fda70744841d.
Report an issue: GitHub.
Appendix: source
Thrown at crates/rnote-engine/src/fileformats/xoppformat.rs:413
"attach" => XoppBackgroundPixmapDomain::Attach,
"clone" => XoppBackgroundPixmapDomain::Clone,
_ => {
return Err(anyhow::anyhow!("Err while parsing `style` attribute of XoppBackground with node id {:?}, is not a valid value", node.id()));
}
};
let filename = node
.attribute("filename")
.ok_or_else(|| {
anyhow::anyhow!("Failed to parse `filename` attribute in XoppBackground with node id {:?}, could not find attribute", node.id())
})?
.to_string();
self.bg_type = XoppBackgroundType::Pixmap { domain, filename };
}
"pdf" => {
self.bg_type = XoppBackgroundType::Pdf;
}
_ => {
return Err(anyhow::anyhow!("Failed to parse `type` attribute of XoppBackground with node id {:?}, is not a valid value", node.id()));
}
}
Ok(())
}
}
impl XmlWritable for XoppBackground {
fn write_to_xml(&self, w: &mut xmlwriter::XmlWriter) {
w.start_element("background");
if let Some(name) = self.name.as_ref() {
w.write_attribute("name", name.as_str());
}
self.bg_type.write_to_xml(w);
w.end_element()
}
}
View on GitHub (pinned to bbc5354502)