flxzt/rnote · error
DocExportFormat try_from
Error message
DocExportFormat try_from::<u32>() for value {} failed What it means
DocExportFormat implements TryFrom<u32> via num_traits::FromPrimitive; a u32 with no matching variant yields this error. It guards numeric export-format identifiers (e.g. png, svg, pdf) read from preferences or IPC.
Solutions
- Validate the u32 against the defined DocExportFormat variants before conversion.
- Use the current rnote version's enum ordering; migrate values from older files.
- Default to a safe format (e.g. PNG) on conversion failure.
- Persist formats by name instead of integer discriminant.
Example fix
// before
let format = DocExportFormat::try_from(raw_u32)?;
// after
let format = DocExportFormat::try_from(raw_u32)
.unwrap_or(DocExportFormat::Png); Defensive patterns
Strategy: validation
Validate before calling
fn is_valid_doc_export_format(v: u32) -> bool {
DocExportFormat::try_from(v).is_ok()
} Type guard
fn as_doc_export_format(v: u32) -> Option<DocExportFormat> {
num_traits::FromPrimitive::from_u32(v)
} Try / catch
match DocExportFormat::try_from(raw) {
Ok(f) => f,
Err(_) => {
log::warn!("unknown export format {raw}; defaulting to PNG");
DocExportFormat::Png
}
} Prevention
- Validate format codes coming from frontends/IPC
- Keep enum ordering stable; add migrations when it changes
- Default to a safe format on invalid input
- Test export flows against saved preferences from older versions
When it happens
Trigger: Calling DocExportFormat::try_from(u32) with an invalid value, typically during export flows that deserialize the requested format from stored prefs or frontend calls.
Common situations: Preferences saved by another rnote version with different discriminants, corrupted settings, or frontends passing out-of-range integer format codes.
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
- DocPagesExportFormat try_from
- SelectionExportFormat try_from
- PatternStyle try_from
- PredefinedFormat try_from
- MeasureUnit try_from
AI-assisted analysis of flxzt/rnote@bbc5354502 (2026-09-08).
Data as JSON: /api/errors/69dc68aa6214acf0.
Report an issue: GitHub.
Appendix: source
Thrown at crates/rnote-engine/src/engine/export.rs:52
Svg,
#[serde(rename = "pdf")]
Pdf,
#[serde(rename = "xopp")]
Xopp,
}
impl Default for DocExportFormat {
fn default() -> Self {
Self::Pdf
}
}
impl TryFrom<u32> for DocExportFormat {
type Error = anyhow::Error;
fn try_from(value: u32) -> Result<Self, Self::Error> {
num_traits::FromPrimitive::from_u32(value).ok_or_else(|| {
anyhow::anyhow!(
"DocExportFormat try_from::<u32>() for value {} failed",
value
)
})
}
}
impl DocExportFormat {
/// File extension for the format.
pub fn file_ext(self) -> String {
match self {
DocExportFormat::Svg => String::from("svg"),
DocExportFormat::Pdf => String::from("pdf"),
DocExportFormat::Xopp => String::from("xopp"),
}
}
}
View on GitHub (pinned to bbc5354502)