iced-rs/iced · error

Line must be parsed

Error message

Line must be parsed

What it means

The markdown parser's line iterator asserts that lines.get(self.current - 1) succeeds with expect("Line must be parsed"). Since current was just incremented, the invariant is that the previous line always exists; a panic means the iterator advanced past the end or was constructed with lines that were never stored, i.e. an off-by-one or empty-lines bug in the parser state.

Solutions

  1. Ensure input is well-formed and doesn't terminate inside an unclosed block; append a trailing newline to the markdown content before parsing.
  2. Check the version of iced_widget - this is an internal invariant; upgrade if a fix for truncated-input handling exists.
  3. If you embed iced's markdown parser, guard block parsers so they stop when current >= lines.len() instead of pulling the next line.
  4. Minimize the failing input to isolate the truncated construct and fix or escape it.

Example fix

// before
let line = self.lines.get(self.current - 1).expect("Line must be parsed");
// after (library-side hardening)
let line = match self.lines.get(self.current.checked_sub(1)?) { Some(l) => l, None => return None };
Defensive patterns

Strategy: validation

Validate before calling

// ensure input ends cleanly before parsing
let md = if source.ends_with('\n') { source.to_string() } else { format!("{source}\n") };

Prevention

When it happens

Trigger: Advancing the line cursor past the last line and then requesting the current line - typically from a parse routine that fails to check whether current exceeds lines.len() before calling the next-line accessor.

Common situations: Markdown input ending abruptly (file ends inside an open block like a code fence or list), causing the parser to peek one line too far; regression from a parser change to the cursor handling.

Related errors


AI-assisted analysis of iced-rs/iced@fa3bae5287 (2026-09-11). Data as JSON: /api/errors/1b64e4f924b25cc7. Report an issue: GitHub.

Appendix: source

Thrown at widget/src/markdown.rs:2476

                            text: text[range].to_owned(),
                            code,
                        });
                    }

                    if self.current == self.lines.len() {
                        self.lines.push((text.to_owned(), spans));
                    } else {
                        self.lines[self.current] = (text.to_owned(), spans);
                    }
                }
            }

            self.current += 1;

            &self
                .lines
                .get(self.current - 1)
                .expect("Line must be parsed")
                .1
        }
    }
}

View on GitHub (pinned to fa3bae5287)