Skip to content

Commit b84a53d

Browse files
teymour-aldridgejstarry
authored andcommitted
Improve html! error messages. (#1192)
* 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.
1 parent 2f241db commit b84a53d

File tree

11 files changed

+53
-53
lines changed

11 files changed

+53
-53
lines changed

yew-macro/src/html_tree/html_component.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl Parse for HtmlComponent {
3636
return match input.parse::<HtmlComponentClose>() {
3737
Ok(close) => Err(syn::Error::new_spanned(
3838
close,
39-
"this close tag has no corresponding open tag",
39+
"this closing tag has no corresponding opening tag",
4040
)),
4141
Err(err) => Err(err),
4242
};
@@ -57,7 +57,7 @@ impl Parse for HtmlComponent {
5757
if input.is_empty() {
5858
return Err(syn::Error::new_spanned(
5959
open,
60-
"this open tag has no corresponding close tag",
60+
"this opening tag has no corresponding closing tag",
6161
));
6262
}
6363
if let Some(ty) = HtmlComponentClose::peek(input.cursor()) {
@@ -376,7 +376,7 @@ impl Props {
376376
}
377377

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

@@ -467,7 +467,7 @@ impl Parse for Props {
467467
p.node_ref = node_ref;
468468
p.key = key;
469469

470-
// alphabetize
470+
// sort alphabetically
471471
p.props.sort_by(|a, b| {
472472
if a.label == b.label {
473473
Ordering::Equal

yew-macro/src/html_tree/html_iterable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl Parse for HtmlIterable {
2626
if err.to_string().starts_with("unexpected end of input") {
2727
Err(syn::Error::new_spanned(
2828
for_token,
29-
"expected expression after `for`",
29+
"expected an expression after the keyword `for`",
3030
))
3131
} else {
3232
Err(err)

yew-macro/src/html_tree/html_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl Parse for HtmlList {
2828
return match input.parse::<HtmlListClose>() {
2929
Ok(close) => Err(syn::Error::new_spanned(
3030
close,
31-
"this close tag has no corresponding open tag",
31+
"this closing tag has no corresponding opening tag",
3232
)),
3333
Err(err) => Err(err),
3434
};
@@ -38,7 +38,7 @@ impl Parse for HtmlList {
3838
if !HtmlList::verify_end(input.cursor()) {
3939
return Err(syn::Error::new_spanned(
4040
open,
41-
"this open tag has no corresponding close tag",
41+
"this opening tag has no corresponding closing tag",
4242
));
4343
}
4444

yew-macro/src/html_tree/html_tag/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl Parse for HtmlTag {
3535
return match input.parse::<HtmlTagClose>() {
3636
Ok(close) => Err(syn::Error::new_spanned(
3737
close,
38-
"this close tag has no corresponding open tag",
38+
"this closing tag has no corresponding opening tag",
3939
)),
4040
Err(err) => Err(err),
4141
};
@@ -56,7 +56,7 @@ impl Parse for HtmlTag {
5656
if input.is_empty() {
5757
return Err(syn::Error::new_spanned(
5858
open,
59-
"this open tag has no corresponding close tag",
59+
"this opening tag has no corresponding closing tag",
6060
));
6161
}
6262
if let Some(next_close_tag_name) = HtmlTagClose::peek(input.cursor()) {

yew-macro/src/html_tree/html_tag/tag_attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl Parse for TagAttributes {
177177
let label = &attributes[i + 1].label;
178178
return Err(syn::Error::new_spanned(
179179
label,
180-
format!("only one `{}` attribute allowed", label),
180+
format!("the attribute `{}` can only be specified once", label),
181181
));
182182
}
183183
i += 1;

yew-macro/src/html_tree/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Parse for HtmlRoot {
5555
let stream: TokenStream = input.parse()?;
5656
Err(syn::Error::new_spanned(
5757
stream,
58-
"only one root html element allowed",
58+
"only one root html element is allowed (hint: you can wrap multiple html elements in a fragment `<></>`)",
5959
))
6060
} else {
6161
Ok(html_root)
@@ -73,7 +73,7 @@ impl ToTokens for HtmlRoot {
7373
impl Parse for HtmlTree {
7474
fn parse(input: ParseStream) -> Result<Self> {
7575
let html_type = HtmlTree::peek(input.cursor())
76-
.ok_or_else(|| input.error("expected valid html element"))?;
76+
.ok_or_else(|| input.error("expected a valid html element"))?;
7777
let html_tree = match html_type {
7878
HtmlType::Empty => HtmlTree::Empty,
7979
HtmlType::Component => HtmlTree::Component(Box::new(input.parse()?)),

yew-macro/tests/macro/html-component-fail.stderr

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: this open tag has no corresponding close tag
1+
error: this opening tag has no corresponding closing tag
22
--> $DIR/html-component-fail.rs:79:13
33
|
44
79 | html! { <Child> };
@@ -30,7 +30,7 @@ error: unexpected token
3030
|
3131
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3232

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

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

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

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

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

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

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

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

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

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

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

185-
error: this close tag has no corresponding open tag
185+
error: this closing tag has no corresponding opening tag
186186
--> $DIR/html-component-fail.rs:118:30
187187
|
188188
118 | html! { <Generic<String>></Generic<Vec<String>>> };

yew-macro/tests/macro/html-iterable-fail.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: expected expression after `for`
1+
error: expected an expression after the keyword `for`
22
--> $DIR/html-iterable-fail.rs:4:13
33
|
44
4 | html! { for };

yew-macro/tests/macro/html-list-fail.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
1-
error: this open tag has no corresponding close tag
1+
error: this opening tag has no corresponding closing tag
22
--> $DIR/html-list-fail.rs:4:13
33
|
44
4 | html! { <> };
55
| ^^
66
|
77
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
88

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

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

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

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

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

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

65-
error: this open tag has no corresponding close tag
65+
error: this opening tag has no corresponding closing tag
6666
--> $DIR/html-list-fail.rs:12:13
6767
|
6868
12 | html! { <key="key".to_string()>invalid</key>}

yew-macro/tests/macro/html-node-fail.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: only one root html element allowed
1+
error: only one root html element is allowed (hint: you can wrap multiple html elements in a fragment `<></>`)
22
--> $DIR/html-node-fail.rs:4:21
33
|
44
4 | html! { "valid" "invalid" };

0 commit comments

Comments
 (0)