Skip to content

Commit

Permalink
Improve html! error messages. (#1192)
Browse files Browse the repository at this point in the history
* Improve `html!` error messages.

* Improved some additional error messages.

* Improved error messages for iterables.

* Improved list error messages.

* Made a comment clearer.

* Updated an `html_tag` error message.

* Improved duplicate attribute error message.

* Updated tests to reflect updated error messages.

* Reformat code.

* Updated tests to reflect new error messages.

* Updated macro tests.

* Fix macro tests.

* Reformat code.
  • Loading branch information
teymour-aldridge authored and mergify[bot] committed May 14, 2020
1 parent 3852076 commit c92dcf3
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 53 deletions.
8 changes: 4 additions & 4 deletions yew-macro/src/html_tree/html_component.rs
Expand Up @@ -36,7 +36,7 @@ impl Parse for HtmlComponent {
return match input.parse::<HtmlComponentClose>() {
Ok(close) => Err(syn::Error::new_spanned(
close,
"this close tag has no corresponding open tag",
"this closing tag has no corresponding opening tag",
)),
Err(err) => Err(err),
};
Expand All @@ -57,7 +57,7 @@ impl Parse for HtmlComponent {
if input.is_empty() {
return Err(syn::Error::new_spanned(
open,
"this open tag has no corresponding close tag",
"this opening tag has no corresponding closing tag",
));
}
if let Some(ty) = HtmlComponentClose::peek(input.cursor()) {
Expand Down Expand Up @@ -376,7 +376,7 @@ impl Props {
}

fn collision_message() -> &'static str {
"Using special syntax `with props` along with named prop is not allowed. This rule does not apply to special `ref` prop"
"Using the `with props` syntax in combination with named props is not allowed (note: this does not apply to the `ref` prop)."
}
}

Expand Down Expand Up @@ -467,7 +467,7 @@ impl Parse for Props {
p.node_ref = node_ref;
p.key = key;

// alphabetize
// sort alphabetically
p.props.sort_by(|a, b| {
if a.label == b.label {
Ordering::Equal
Expand Down
2 changes: 1 addition & 1 deletion yew-macro/src/html_tree/html_iterable.rs
Expand Up @@ -26,7 +26,7 @@ impl Parse for HtmlIterable {
if err.to_string().starts_with("unexpected end of input") {
Err(syn::Error::new_spanned(
for_token,
"expected expression after `for`",
"expected an expression after the keyword `for`",
))
} else {
Err(err)
Expand Down
4 changes: 2 additions & 2 deletions yew-macro/src/html_tree/html_list.rs
Expand Up @@ -28,7 +28,7 @@ impl Parse for HtmlList {
return match input.parse::<HtmlListClose>() {
Ok(close) => Err(syn::Error::new_spanned(
close,
"this close tag has no corresponding open tag",
"this closing tag has no corresponding opening tag",
)),
Err(err) => Err(err),
};
Expand All @@ -38,7 +38,7 @@ impl Parse for HtmlList {
if !HtmlList::verify_end(input.cursor()) {
return Err(syn::Error::new_spanned(
open,
"this open tag has no corresponding close tag",
"this opening tag has no corresponding closing tag",
));
}

Expand Down
4 changes: 2 additions & 2 deletions yew-macro/src/html_tree/html_tag/mod.rs
Expand Up @@ -35,7 +35,7 @@ impl Parse for HtmlTag {
return match input.parse::<HtmlTagClose>() {
Ok(close) => Err(syn::Error::new_spanned(
close,
"this close tag has no corresponding open tag",
"this closing tag has no corresponding opening tag",
)),
Err(err) => Err(err),
};
Expand All @@ -56,7 +56,7 @@ impl Parse for HtmlTag {
if input.is_empty() {
return Err(syn::Error::new_spanned(
open,
"this open tag has no corresponding close tag",
"this opening tag has no corresponding closing tag",
));
}
if let Some(next_close_tag_name) = HtmlTagClose::peek(input.cursor()) {
Expand Down
2 changes: 1 addition & 1 deletion yew-macro/src/html_tree/html_tag/tag_attributes.rs
Expand Up @@ -177,7 +177,7 @@ impl Parse for TagAttributes {
let label = &attributes[i + 1].label;
return Err(syn::Error::new_spanned(
label,
format!("only one `{}` attribute allowed", label),
format!("the attribute `{}` can only be specified once", label),
));
}
i += 1;
Expand Down
4 changes: 2 additions & 2 deletions yew-macro/src/html_tree/mod.rs
Expand Up @@ -55,7 +55,7 @@ impl Parse for HtmlRoot {
let stream: TokenStream = input.parse()?;
Err(syn::Error::new_spanned(
stream,
"only one root html element allowed",
"only one root html element is allowed (hint: you can wrap multiple html elements in a fragment `<></>`)",
))
} else {
Ok(html_root)
Expand All @@ -73,7 +73,7 @@ impl ToTokens for HtmlRoot {
impl Parse for HtmlTree {
fn parse(input: ParseStream) -> Result<Self> {
let html_type = HtmlTree::peek(input.cursor())
.ok_or_else(|| input.error("expected valid html element"))?;
.ok_or_else(|| input.error("expected a valid html element"))?;
let html_tree = match html_type {
HtmlType::Empty => HtmlTree::Empty,
HtmlType::Component => HtmlTree::Component(Box::new(input.parse()?)),
Expand Down
26 changes: 13 additions & 13 deletions yew-macro/tests/macro/html-component-fail.stderr
@@ -1,4 +1,4 @@
error: this open tag has no corresponding close tag
error: this opening tag has no corresponding closing tag
--> $DIR/html-component-fail.rs:79:13
|
79 | html! { <Child> };
Expand Down Expand Up @@ -30,7 +30,7 @@ error: unexpected token
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: this open tag has no corresponding close tag
error: this opening tag has no corresponding closing tag
--> $DIR/html-component-fail.rs:83:13
|
83 | html! { <Child with props > };
Expand All @@ -54,31 +54,31 @@ error: too many refs set
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: Using special syntax `with props` along with named prop is not allowed. This rule does not apply to special `ref` prop
error: Using the `with props` syntax in combination with named props is not allowed (note: this does not apply to the `ref` prop).
--> $DIR/html-component-fail.rs:86:38
|
86 | html! { <Child with props ref=() value=1 ref=() /> };
| ^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: Using special syntax `with props` along with named prop is not allowed. This rule does not apply to special `ref` prop
error: Using the `with props` syntax in combination with named props is not allowed (note: this does not apply to the `ref` prop).
--> $DIR/html-component-fail.rs:87:31
|
87 | html! { <Child with props value=1 ref=() ref=() /> };
| ^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: Using special syntax `with props` along with named prop is not allowed. This rule does not apply to special `ref` prop
error: Using the `with props` syntax in combination with named props is not allowed (note: this does not apply to the `ref` prop).
--> $DIR/html-component-fail.rs:88:28
|
88 | html! { <Child value=1 with props ref=() ref=() /> };
| ^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: Using special syntax `with props` along with named prop is not allowed. This rule does not apply to special `ref` prop
error: Using the `with props` syntax in combination with named props is not allowed (note: this does not apply to the `ref` prop).
--> $DIR/html-component-fail.rs:89:35
|
89 | html! { <Child value=1 ref=() with props ref=() /> };
Expand All @@ -102,15 +102,15 @@ error: unexpected token
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: Using special syntax `with props` along with named prop is not allowed. This rule does not apply to special `ref` prop
error: Using the `with props` syntax in combination with named props is not allowed (note: this does not apply to the `ref` prop).
--> $DIR/html-component-fail.rs:93:28
|
93 | html! { <Child value=1 with props /> };
| ^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: Using special syntax `with props` along with named prop is not allowed. This rule does not apply to special `ref` prop
error: Using the `with props` syntax in combination with named props is not allowed (note: this does not apply to the `ref` prop).
--> $DIR/html-component-fail.rs:94:31
|
94 | html! { <Child with props value=1 /> };
Expand Down Expand Up @@ -150,39 +150,39 @@ error: too many refs set
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: this close tag has no corresponding open tag
error: this closing tag has no corresponding opening tag
--> $DIR/html-component-fail.rs:106:13
|
106 | html! { </Child> };
| ^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: this open tag has no corresponding close tag
error: this opening tag has no corresponding closing tag
--> $DIR/html-component-fail.rs:107:13
|
107 | html! { <Child><Child></Child> };
| ^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: only one root html element allowed
error: only one root html element is allowed (hint: you can wrap multiple html elements in a fragment `<></>`)
--> $DIR/html-component-fail.rs:108:28
|
108 | html! { <Child></Child><Child></Child> };
| ^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: this close tag has no corresponding open tag
error: this closing tag has no corresponding opening tag
--> $DIR/html-component-fail.rs:117:30
|
117 | html! { <Generic<String>></Generic> };
| ^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: this close tag has no corresponding open tag
error: this closing tag has no corresponding opening tag
--> $DIR/html-component-fail.rs:118:30
|
118 | html! { <Generic<String>></Generic<Vec<String>>> };
Expand Down
2 changes: 1 addition & 1 deletion yew-macro/tests/macro/html-iterable-fail.stderr
@@ -1,4 +1,4 @@
error: expected expression after `for`
error: expected an expression after the keyword `for`
--> $DIR/html-iterable-fail.rs:4:13
|
4 | html! { for };
Expand Down
16 changes: 8 additions & 8 deletions yew-macro/tests/macro/html-list-fail.stderr
@@ -1,52 +1,52 @@
error: this open tag has no corresponding close tag
error: this opening tag has no corresponding closing tag
--> $DIR/html-list-fail.rs:4:13
|
4 | html! { <> };
| ^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: this close tag has no corresponding open tag
error: this closing tag has no corresponding opening tag
--> $DIR/html-list-fail.rs:5:13
|
5 | html! { </> };
| ^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: this open tag has no corresponding close tag
error: this opening tag has no corresponding closing tag
--> $DIR/html-list-fail.rs:6:13
|
6 | html! { <><> };
| ^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: this close tag has no corresponding open tag
error: this closing tag has no corresponding opening tag
--> $DIR/html-list-fail.rs:7:13
|
7 | html! { </></> };
| ^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: this open tag has no corresponding close tag
error: this opening tag has no corresponding closing tag
--> $DIR/html-list-fail.rs:8:13
|
8 | html! { <><></> };
| ^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: only one root html element allowed
error: only one root html element is allowed (hint: you can wrap multiple html elements in a fragment `<></>`)
--> $DIR/html-list-fail.rs:9:18
|
9 | html! { <></><></> };
| ^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected valid html element
error: expected a valid html element
--> $DIR/html-list-fail.rs:10:15
|
10 | html! { <>invalid</> };
Expand All @@ -62,7 +62,7 @@ error: unexpected end of input, expected expression
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: this open tag has no corresponding close tag
error: this opening tag has no corresponding closing tag
--> $DIR/html-list-fail.rs:12:13
|
12 | html! { <key="key".to_string()>invalid</key>}
Expand Down
2 changes: 1 addition & 1 deletion yew-macro/tests/macro/html-node-fail.stderr
@@ -1,4 +1,4 @@
error: only one root html element allowed
error: only one root html element is allowed (hint: you can wrap multiple html elements in a fragment `<></>`)
--> $DIR/html-node-fail.rs:4:21
|
4 | html! { "valid" "invalid" };
Expand Down

0 comments on commit c92dcf3

Please sign in to comment.