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.
Source
Thrown at widget/src/markdown.rs:1857
text: text[range].to_owned(),
code,
});
}
if self.current + 1 == self.lines.len() {
let _ = self.lines.pop();
}
self.lines.push((text.to_owned(), spans));
}
}
self.current += 1;
&self
.lines
.get(self.current - 1)
.expect("Line must be parsed")
.1
}
}
}
#[cfg(test)]
mod tests {
use super::*;
fn groups<const N: usize>(items: &[Item]) -> [(Option<&Item>, &[Item]); N] {
sections(items)
.collect::<Vec<_>>()
.try_into()
.expect("Unexpected number of sections")
}
fn assert_same_items<'a>(
left: impl IntoIterator<Item = &'a Item>,View on GitHub (pinned to d146509d89)
Solutions
- Ensure input is well-formed and doesn't terminate inside an unclosed block; append a trailing newline to the markdown content before parsing.
- Check the version of iced_widget - this is an internal invariant; upgrade if a fix for truncated-input handling exists.
- If you embed iced's markdown parser, guard block parsers so they stop when current >= lines.len() instead of pulling the next line.
- 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
- Always terminate markdown content with a trailing newline.
- Avoid truncating streamed markdown before rendering; render only complete blocks.
- Reproduce panics with minimal inputs and upgrade iced when fixed.
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@d146509d89 (2026-09-11).
Data as JSON: /api/errors/1b64e4f924b25cc7.
Report an issue: GitHub.