flxzt/rnote · error

Err while parsing `style` attribute of XoppBackground

Error message

Err while parsing `style` attribute of XoppBackground, {:?} is not a valid value

What it means

XoppBackgroundSolidStyle::from_xml_attr_value received a 'style' attribute value that is not one of the known solid background styles (plain, ruled, lined, staves, graph, dotted, isodotted, isograph). The parser rejects unknown enum values.

Solutions

  1. Check the style value against valid names: plain, ruled, lined, staves, graph, dotted, isodotted, isograph
  2. Open and re-save the file in Xournal++ to normalize the style
  3. Note: in the XoppBackground loader path (error 105) this error is caught and style falls back to Plain; only direct parsing propagates it
  4. Update the engine if the file uses a style added in a newer Xournal++ version

Example fix

// before
<background type="solid" style="college-ruled"/>
// after
<background type="solid" style="ruled"/>
Defensive patterns

Strategy: validation

Validate before calling

const SOLID_STYLES: &[&str] = &["plain","ruled","lined","staves","graph","dotted","isodotted","isograph"];
fn style_is_valid(s: &str) -> bool { SOLID_STYLES.contains(&s) }

Try / catch

match XoppBackgroundSolidStyle::from_xml_attr_value(style) {
    Ok(s) => s,
    Err(e) => {
        log::warn!("unknown solid style, defaulting to Plain: {e}");
        XoppBackgroundSolidStyle::Plain
    }
}

Prevention

When it happens

Trigger: Parsing a <background type="solid" style="..."> node whose style string is unrecognized, e.g. a style added by a newer Xournal++ or misspelled by hand.

Common situations: Files from newer Xournal++ versions with new background styles; typos when editing XML manually; custom exporters emitting nonstandard style names.

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.

Related errors


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

Appendix: source

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

        }
    }
}

impl FromXmlAttributeValue for XoppBackgroundSolidStyle {
    fn from_xml_attr_value(s: &str) -> Result<Self, anyhow::Error>
    where
        Self: Sized,
    {
        match s {
            "plain" => Ok(Self::Plain),
            "ruled" => Ok(Self::Ruled),
            "lined" => Ok(Self::Lined),
            "staves" => Ok(Self::Staves),
            "graph" => Ok(Self::Graph),
            "dotted" => Ok(Self::Dotted),
            "isodotted" => Ok(Self::IsometricDotted),
            "isograph" => Ok(Self::IsometricGraph),
            o => Err(anyhow::anyhow!(
                "Err while parsing `style` attribute of XoppBackground, {:?} is not a valid value",
                o
            )),
        }
    }
}

/// The Xopp background pixmap domain.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum XoppBackgroundPixmapDomain {
    /// Absolute.
    Absolute,
    /// Attach.
    Attach,
    /// Clone.
    Clone,
}

View on GitHub (pinned to bbc5354502)