flxzt/rnote · error

Layout from_string failed, invalid name

Error message

Layout from_string failed, invalid name: {s}

What it means

Layout's FromStr parses layout names like "fixed-size", "continuous-vertical", "semi-infinite", and "infinite"; any other string produces this error naming the invalid input. It is the string-based counterpart to the numeric TryFrom conversion.

Solutions

  1. Use one of the exact accepted names: fixed-size, continuous-vertical, semi-infinite, infinite.
  2. Normalize input (trim, lowercase) before parsing.
  3. Validate/autocomplete the layout name against the known variants in UI or CLI code.
  4. Fall back to the default Layout when parsing fails.

Example fix

// before
let layout: Layout = user_input.parse()?;
// after
let layout: Layout = user_input.trim().to_lowercase().parse()
    .unwrap_or(Layout::default());
Defensive patterns

Strategy: validation

Validate before calling

const LAYOUT_NAMES: [&str; 4] = ["fixed-size", "continuous-vertical", "semi-infinite", "infinite"];
fn is_valid_layout_name(s: &str) -> bool {
    LAYOUT_NAMES.contains(&s)
}

Type guard

fn parse_layout(s: &str) -> Option<Layout> {
    s.parse::<Layout>().ok()
}

Try / catch

match user_input.parse::<Layout>() {
    Ok(l) => l,
    Err(e) => {
        eprintln!("invalid layout name: {e}");
        Layout::default()
    }
}

Prevention

When it happens

Trigger: Calling "fixed-size".parse::<Layout>() or Layout::from_str with a misspelled, differently-cased, or unknown layout name string.

Common situations: Typo'd layout names in config files or CLI arguments, strings persisted by older versions with renamed variants, and user-supplied input not validated before parsing.

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/6033133d5896c13f. Report an issue: GitHub.

Appendix: source

Thrown at crates/rnote-engine/src/document/layout.rs:54

impl TryFrom<u32> for Layout {
    type Error = anyhow::Error;

    fn try_from(value: u32) -> Result<Self, Self::Error> {
        num_traits::FromPrimitive::from_u32(value)
            .ok_or_else(|| anyhow::anyhow!("Layout try_from::<u32>() for value {} failed", value))
    }
}

impl std::str::FromStr for Layout {
    type Err = anyhow::Error;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "fixed-size" => Ok(Self::FixedSize),
            "continuous-vertical" => Ok(Self::ContinuousVertical),
            "semi-infinite" => Ok(Self::SemiInfinite),
            "infinite" => Ok(Self::Infinite),
            s => Err(anyhow::anyhow!(
                "Layout from_string failed, invalid name: {s}"
            )),
        }
    }
}

impl Display for Layout {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Layout::FixedSize => write!(f, "fixed-size"),
            Layout::ContinuousVertical => write!(f, "continuous-vertical"),
            Layout::SemiInfinite => write!(f, "semi-infinite"),
            Layout::Infinite => write!(f, "infinite"),
        }
    }
}

impl Layout {

View on GitHub (pinned to bbc5354502)