flxzt/rnote · error

Failed to parse `color` attribute in XoppBackground with id

Error message

Failed to parse `color` attribute in XoppBackground with id {:?}

What it means

For a solid XoppBackground, the 'color' attribute is mandatory and must be parseable by XoppColor::from_backgroundcolor_attr_value. This error is returned when the attribute is absent (or the parse itself fails, as the ? propagates both).

Solutions

  1. Add a color attribute in #rrggbbaa form, e.g. color="#ffffffff"
  2. Ensure the hex string includes the alpha channel (8 hex digits)
  3. Re-save the file in Xournal++ to emit canonical color values
  4. Check for whitespace or '#' prefix issues in the attribute

Example fix

// before
<background type="solid" style="plain" color="#ffffff"/>
// after
<background type="solid" style="plain" color="#ffffffff"/>
Defensive patterns

Strategy: validation

Validate before calling

fn valid_bg_color(node: &roxmltree::Node) -> bool {
    node.attribute("color")
        .map(|c| c.starts_with('#') && c.len() == 9) // #rrggbbaa
        .unwrap_or(false)
}

Try / catch

match XoppColor::from_backgroundcolor_attr_value(color_str) {
    Ok(c) => c,
    Err(e) => bail!("bad background color {:?}: {}", color_str, e),
}

Prevention

When it happens

Trigger: load_from_xml on a <background type="solid"> node with no 'color' attribute, or a color string that fails backgroundcolor parsing (e.g. missing alpha channel in #rrggbbaa).

Common situations: Files edited to remove color; exporters emitting 6-digit hex where 8-digit with alpha is expected; case/format mistakes like '0xffffff'.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

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

            anyhow::anyhow!(
                "failed to parse `type` attribute of XoppBackground with node id {:?}, could not find attribute",
                node.id()
            )
        })? {
            "solid" => {
                let style = match XoppBackgroundSolidStyle::from_xml_attr_value(node.attribute("style").ok_or_else(|| {
                    anyhow::anyhow!("failed to parse `style` attribute in XoppBackground with node id {:?}, could not find attribute", node.id())
                })?) {
                    Ok(s) => s,
                    Err(e) => {
                        error!("Failed to retrieve the XoppBackgroundSolidStyle from `style` attribute, Err: {e:?}");
                        XoppBackgroundSolidStyle::Plain
                    }
                };

                let color = XoppColor::from_backgroundcolor_attr_value(
                    node.attribute("color").ok_or_else(|| {
                        anyhow::anyhow!(
                            "Failed to parse `color` attribute in XoppBackground with id {:?}",
                            node.id()
                        )
                    })?,
                )?;
                self.bg_type = XoppBackgroundType::Solid { color, style };
            }
            "pixmap" => {
                let domain = match node.attribute("domain").ok_or_else(|| {
                    anyhow::anyhow!("Failed to parse `domain` attribute in XoppBackground with node id {:?}, could not find attribute", node.id())
                })? {
                    "absolute" => XoppBackgroundPixmapDomain::Absolute,
                    "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()));
                    }
                };

View on GitHub (pinned to bbc5354502)