Skip to content

Commit

Permalink
refactor: better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
stoically committed Sep 10, 2020
1 parent 5b4b862 commit 2041904
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use syn::{
parse::{discouraged::Speculative, Parse, ParseStream, Parser as _, Peek},
punctuated::Punctuated,
token::{Brace, Colon},
Expr, ExprBlock, ExprLit, ExprPath, Ident, Path, PathSegment, Result, Token,
Error, Expr, ExprBlock, ExprLit, ExprPath, Ident, Path, PathSegment, Result, Token,
};

use crate::{node::*, punctuation::*};
Expand Down Expand Up @@ -172,7 +172,10 @@ impl Parser {
fn has_children(&self, tag_open_name: &NodeName, input: ParseStream) -> Result<bool> {
// an empty input at this point means the tag wasn't closed
if input.is_empty() {
return Err(input.error("open tag has no corresponding close tag"));
return Err(Error::new(
tag_open_name.span(),
"open tag has no corresponding close tag",
));
}

if let Ok(tag_close_name) = self.tag_close(&input.fork()) {
Expand All @@ -199,7 +202,7 @@ impl Parser {
}

if input.is_empty() {
return Err(input.error("expected valid attribute or closing caret >"));
return Err(input.error("expected closing caret >"));
}

let next: TokenTree = input.parse()?;
Expand Down Expand Up @@ -260,7 +263,7 @@ impl Parser {
let eq = fork.parse::<Option<Token![=]>>()?;
let value = if eq.is_some() {
if fork.is_empty() {
return Err(fork.error("missing attribute value"));
return Err(Error::new(key.span(), "missing attribute value"));
}

if fork.peek(Brace) {
Expand Down

0 comments on commit 2041904

Please sign in to comment.