From 83f4d18fd3da62392559977b747178ba3186057b Mon Sep 17 00:00:00 2001 From: Jan Range Date: Fri, 15 Nov 2024 20:09:12 +0100 Subject: [PATCH] return `Validator` when parsing fails --- src/markdown/parser.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/markdown/parser.rs b/src/markdown/parser.rs index d333fbb..5c6eac1 100644 --- a/src/markdown/parser.rs +++ b/src/markdown/parser.rs @@ -69,7 +69,7 @@ enum ParserState { /// # Returns /// /// A `Result` containing a `DataModel` on success or an error on failure. -pub fn parse_markdown(content: &str) -> Result> { +pub fn parse_markdown(content: &str) -> Result { // Remove HTML and links let content = clean_content(content); @@ -106,12 +106,16 @@ pub fn parse_markdown(content: &str) -> Result> { // Add internal types, if used add_internal_types(&mut model); - // Apply inheritance - add_parent_types(&mut model)?; + // Apply inheritance (THIS NEEDS TO BE SPLIT INTO A SEPARATE FUNCTION) + add_parent_types(&mut model).expect("Failed to add parent types"); // Validate the model let mut validator = Validator::new(); - validator.validate(&model)?; + validator.validate(&model); + + if !validator.is_valid { + return Err(validator); + } Ok(model) } @@ -121,8 +125,8 @@ fn clean_content(content: &str) -> String { let re = Regex::new(r"<[^>]*>").unwrap(); let content = re.replace_all(content, "").to_string(); - // Remove all markdown links - let re = Regex::new(r"\[([^\]]+)\]\([^\)]+\)").unwrap(); + // Remove all Markdown links + let re = Regex::new(r"\[([^]]+)]\([^)]+\)").unwrap(); let content = re.replace_all(content.as_str(), "$1").to_string(); content @@ -138,7 +142,7 @@ fn clean_content(content: &str) -> String { /// * `model` - A mutable reference to the data model. fn process_object_event( iterator: &mut Parser, - objects: &mut Vec, + objects: &mut Vec, event: Event, model: &mut DataModel, state: &mut ParserState,