LGUG2Z/komorebi · error

the layout file provided was invalid

Error message

the layout file provided was invalid

What it means

After parsing the custom layout file, from_path validates it with layout.is_valid() and bails if the structure is semantically invalid even though it parsed as JSON/YAML. This guards against layouts that deserialize but define no usable windows/columns.

Source

Thrown at komorebi-layouts/src/custom_layout.rs:46

        &mut self.0
    }
}

impl CustomLayout {
    pub fn from_path<P: AsRef<Path>>(path: P) -> eyre::Result<Self> {
        let path = path.as_ref();
        let layout: Self = match path.extension() {
            Some(extension) if extension == "yaml" || extension == "yml" => {
                serde_json::from_reader(BufReader::new(File::open(path)?))?
            }
            Some(extension) if extension == "json" => {
                serde_json::from_reader(BufReader::new(File::open(path)?))?
            }
            _ => bail!("custom layouts must be json or yaml files"),
        };

        if !layout.is_valid() {
            bail!("the layout file provided was invalid");
        }

        Ok(layout)
    }

    #[must_use]
    pub fn column_with_idx(&self, idx: usize) -> (usize, Option<&Column>) {
        let column_idx = self.column_for_container_idx(idx);
        let column = self.get(column_idx);
        (column_idx, column)
    }

    #[must_use]
    pub fn primary_idx(&self) -> Option<usize> {
        for (i, column) in self.iter().enumerate() {
            if let Column::Primary(_) = column {
                return Option::from(i);
            }

View on GitHub (pinned to e0709f02bf)

Solutions

  1. Validate the layout content: ensure it defines the expected windows/columns/rows structure per the custom layout schema.
  2. Start from a known-good example layout and edit incrementally.
  3. Check for truncated or empty files (cat the file; confirm full content was saved).

Example fix

// before
{ "columns": [] }            // parses but is invalid
// after
{ "columns": [ { "windows": [ { "width_percentage": 50 } ] } ] }
Defensive patterns

Strategy: validation

Validate before calling

let layout: CustomLayout = serde_json::from_str(&std::fs::read_to_string(path)?)?;
if !layout.is_valid() { eprintln!("layout structurally invalid: check windows/columns"); }

Try / catch

match CustomLayout::from_path(&path) {
    Ok(l) if l.is_valid() => l,
    _ => eprintln!("layout invalid or failed to validate; start from a known-good example"),
}

Prevention

When it happens

Trigger: Calling CustomLayout::from_path with a syntactically valid json/yaml file whose content fails is_valid() — e.g. empty layout, zero windows, malformed rows/columns structure.

Common situations: Hand-editing a layout and deleting required fields; copy-pasting an incomplete example; a truncated file that still parses; wrong schema version of layout format.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of LGUG2Z/komorebi@e0709f02bf (2026-09-06). Data as JSON: /api/errors/ffaf565ad198ef0b. Report an issue: GitHub.