Skip to content

Commit c1ab5ba

Browse files
guyernestclaude
andcommitted
fix: skip non-exercise files gracefully in render_example
Handle UnknownExerciseType error by printing a message and returning instead of panicking. This allows the CI to render examples/*.md without failing on README.md or other non-exercise files. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 48066b3 commit c1ab5ba

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

examples/render_example.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use mdbook_exercises::{parse_exercise, render_exercise, ParsedExercise};
1+
use mdbook_exercises::{parse_exercise, render_exercise, ParsedExercise, ParseError};
22
use std::fs;
33
use std::path::Path;
44

@@ -16,9 +16,15 @@ fn main() {
1616
.unwrap_or_else(|_| panic!("Could not read {}", input_path));
1717

1818
// Parse it
19-
println!("Parsing exercise...");
20-
let parsed = parse_exercise(&markdown)
21-
.expect("Failed to parse exercise");
19+
println!("Parsing {}...", input_path);
20+
let parsed = match parse_exercise(&markdown) {
21+
Ok(p) => p,
22+
Err(ParseError::UnknownExerciseType) => {
23+
println!("Skipping {} - not an exercise file (no ::: exercise or ::: usecase directive)", input_path);
24+
return;
25+
}
26+
Err(e) => panic!("Failed to parse exercise: {}", e),
27+
};
2228

2329
// Extract info based on exercise type
2430
let (id, title_opt) = match &parsed {

0 commit comments

Comments
 (0)