flxzt/rnote · error

failed to parse `x` attribute in XoppText with node id

Error message

failed to parse `x` attribute in XoppText with node id {:?}, could not find attribute

What it means

Thrown by XoppText::load_from_xml when a `<text>` element has no `x` attribute. The x coordinate is parsed as f64 and is required to position the text on the page, so its absence aborts parsing with this error naming the node id.

Solutions

  1. Add an x attribute to the <text> element, e.g. x="100.0".
  2. Regenerate the file ensuring font, size, x, y, and color are all present on every <text> element.
  3. Re-save the file in Xournal++ and import the normalized copy.

Example fix

// before (file XML)
<text font="Sans" size="12" y="20">Hello</text>
// after (file XML)
<text font="Sans" size="12" x="100" y="20">Hello</text>
Defensive patterns

Strategy: validation

Validate before calling

fn text_has_x(xml: &str) -> Result<(), String> {
    for (i, chunk) in xml.split("<text").skip(1).enumerate() {
        let head = chunk.split('>').next().unwrap_or("");
        if !head.contains("x=") {
            return Err(format!("text #{i} missing `x` attribute"));
        }
    }
    Ok(())
}

Type guard

fn has_numeric_attr(attrs: &[(&str, &str)], name: &str) -> bool {
    attrs.iter().any(|(k, v)| *k == name && v.parse::<f64>().is_ok())
}

Try / catch

match import_xopp(path) {
    Err(e) if e.to_string().contains("`x` attribute in XoppText") => {
        eprintln!("Text element missing x coordinate; add it or re-save in Xournal++: {e:#}");
    }
    Err(e) => eprintln!("import failed: {e:#}"),
    Ok(doc) => { /* proceed */ }
}

Prevention

When it happens

Trigger: Importing a .xopp file whose <text> element lacks the `x` position attribute — generated by external tools, hand-edited, or corrupted/truncated files.

Common situations: Programmatic xopp generation omitting coordinates; manual XML editing; partial file writes losing attributes.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of flxzt/rnote@bbc5354502 (2026-09-08). Data as JSON: /api/errors/b2443f565662e323. Report an issue: GitHub.

Appendix: source

Thrown at crates/rnote-engine/src/fileformats/xoppformat.rs:887

                    node.id()
                )
            })?
            .to_string();

        self.size = node
            .attribute("size")
            .ok_or_else(|| {
                anyhow::anyhow!(
                    "failed to parse `size` attribute in XoppText with node id {:?}, could not find attribute",
                    node.id()
                )
            })?
            .parse::<f64>()?;

        self.x = node
            .attribute("x")
            .ok_or_else(|| {
                anyhow::anyhow!(
                    "failed to parse `x` attribute in XoppText with node id {:?}, could not find attribute",
                    node.id()
                )
            })?
            .parse::<f64>()?;

        self.y = node
            .attribute("y")
            .ok_or_else(|| {
                anyhow::anyhow!(
                    "failed to parse `y` attribute in XoppText with node id {:?}, could not find attribute",
                    node.id()
                )
            })?
            .parse::<f64>()?;

        self.color =
            XoppColor::from_strokecolor_attr_value(node.attribute("color").ok_or_else(|| {

View on GitHub (pinned to bbc5354502)