From d55765a9b1b2bac905c71e7ec25da7465d2583c6 Mon Sep 17 00:00:00 2001 From: Teymour Aldridge <42674621+teymour-aldridge@users.noreply.github.com> Date: Sun, 10 May 2020 16:26:45 +0100 Subject: [PATCH] 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. --- yew-macro/src/html_tree/html_component.rs | 8 ++--- yew-macro/src/html_tree/html_iterable.rs | 2 +- yew-macro/src/html_tree/html_list.rs | 4 +-- yew-macro/src/html_tree/html_tag/mod.rs | 4 +-- .../src/html_tree/html_tag/tag_attributes.rs | 2 +- yew-macro/src/html_tree/mod.rs | 4 +-- .../tests/macro/html-component-fail.stderr | 26 +++++++------- .../tests/macro/html-iterable-fail.stderr | 2 +- yew-macro/tests/macro/html-list-fail.stderr | 16 ++++----- yew-macro/tests/macro/html-node-fail.stderr | 2 +- yew-macro/tests/macro/html-tag-fail.stderr | 36 +++++++++---------- 11 files changed, 53 insertions(+), 53 deletions(-) diff --git a/yew-macro/src/html_tree/html_component.rs b/yew-macro/src/html_tree/html_component.rs index b0124c238dd..6efdd87d764 100644 --- a/yew-macro/src/html_tree/html_component.rs +++ b/yew-macro/src/html_tree/html_component.rs @@ -36,7 +36,7 @@ impl Parse for HtmlComponent { return match input.parse::() { 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), }; @@ -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()) { @@ -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)." } } @@ -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 diff --git a/yew-macro/src/html_tree/html_iterable.rs b/yew-macro/src/html_tree/html_iterable.rs index 712a018f55a..955a78016ac 100644 --- a/yew-macro/src/html_tree/html_iterable.rs +++ b/yew-macro/src/html_tree/html_iterable.rs @@ -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) diff --git a/yew-macro/src/html_tree/html_list.rs b/yew-macro/src/html_tree/html_list.rs index 1f3e83622b1..5c08fbc5043 100644 --- a/yew-macro/src/html_tree/html_list.rs +++ b/yew-macro/src/html_tree/html_list.rs @@ -28,7 +28,7 @@ impl Parse for HtmlList { return match input.parse::() { 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), }; @@ -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", )); } diff --git a/yew-macro/src/html_tree/html_tag/mod.rs b/yew-macro/src/html_tree/html_tag/mod.rs index 834d56ce542..91922bad01d 100644 --- a/yew-macro/src/html_tree/html_tag/mod.rs +++ b/yew-macro/src/html_tree/html_tag/mod.rs @@ -35,7 +35,7 @@ impl Parse for HtmlTag { return match input.parse::() { 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), }; @@ -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()) { diff --git a/yew-macro/src/html_tree/html_tag/tag_attributes.rs b/yew-macro/src/html_tree/html_tag/tag_attributes.rs index 60ce0e61888..a4f3b1d6c1a 100644 --- a/yew-macro/src/html_tree/html_tag/tag_attributes.rs +++ b/yew-macro/src/html_tree/html_tag/tag_attributes.rs @@ -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; diff --git a/yew-macro/src/html_tree/mod.rs b/yew-macro/src/html_tree/mod.rs index afac21c8824..76c886bec79 100644 --- a/yew-macro/src/html_tree/mod.rs +++ b/yew-macro/src/html_tree/mod.rs @@ -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) @@ -73,7 +73,7 @@ impl ToTokens for HtmlRoot { impl Parse for HtmlTree { fn parse(input: ParseStream) -> Result { 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()?)), diff --git a/yew-macro/tests/macro/html-component-fail.stderr b/yew-macro/tests/macro/html-component-fail.stderr index 12744668add..39dd21f9478 100644 --- a/yew-macro/tests/macro/html-component-fail.stderr +++ b/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! { }; @@ -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! { }; @@ -54,7 +54,7 @@ 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! { }; @@ -62,7 +62,7 @@ error: Using special syntax `with props` along with named prop is not allowed. T | = 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! { }; @@ -70,7 +70,7 @@ error: Using special syntax `with props` along with named prop is not allowed. T | = 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! { }; @@ -78,7 +78,7 @@ error: Using special syntax `with props` along with named prop is not allowed. T | = 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! { }; @@ -102,7 +102,7 @@ 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! { }; @@ -110,7 +110,7 @@ error: Using special syntax `with props` along with named prop is not allowed. T | = 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! { }; @@ -150,7 +150,7 @@ 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! { }; @@ -158,7 +158,7 @@ error: this close tag has no corresponding open tag | = 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! { }; @@ -166,7 +166,7 @@ error: this open tag has no corresponding close tag | = 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! { }; @@ -174,7 +174,7 @@ error: only one root html element allowed | = 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! { > }; @@ -182,7 +182,7 @@ error: this close tag has no corresponding open tag | = 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! { >>> }; diff --git a/yew-macro/tests/macro/html-iterable-fail.stderr b/yew-macro/tests/macro/html-iterable-fail.stderr index ce71d45531c..9a91575233c 100644 --- a/yew-macro/tests/macro/html-iterable-fail.stderr +++ b/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 }; diff --git a/yew-macro/tests/macro/html-list-fail.stderr b/yew-macro/tests/macro/html-list-fail.stderr index a3fea8a6809..971f77bdbfe 100644 --- a/yew-macro/tests/macro/html-list-fail.stderr +++ b/yew-macro/tests/macro/html-list-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-list-fail.rs:4:13 | 4 | html! { <> }; @@ -6,7 +6,7 @@ error: this open tag has no corresponding close tag | = 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! { }; @@ -14,7 +14,7 @@ error: this close tag has no corresponding open tag | = 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! { <><> }; @@ -22,7 +22,7 @@ error: this open tag has no corresponding close tag | = 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! { }; @@ -30,7 +30,7 @@ error: this close tag has no corresponding open tag | = 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! { <><> }; @@ -38,7 +38,7 @@ error: this open tag has no corresponding close tag | = 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! { <><> }; @@ -46,7 +46,7 @@ error: only one root html element allowed | = 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 }; @@ -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! { invalid} diff --git a/yew-macro/tests/macro/html-node-fail.stderr b/yew-macro/tests/macro/html-node-fail.stderr index 9446d747a0c..89ea5687a89 100644 --- a/yew-macro/tests/macro/html-node-fail.stderr +++ b/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" }; diff --git a/yew-macro/tests/macro/html-tag-fail.stderr b/yew-macro/tests/macro/html-tag-fail.stderr index d13496e52fd..37946af2056 100644 --- a/yew-macro/tests/macro/html-tag-fail.stderr +++ b/yew-macro/tests/macro/html-tag-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-tag-fail.rs:6:13 | 6 | html! {
}; @@ -6,7 +6,7 @@ error: this open tag has no corresponding close tag | = 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-tag-fail.rs:7:18 | 7 | html! {
}; @@ -14,7 +14,7 @@ error: this open tag has no corresponding close tag | = 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-tag-fail.rs:8:13 | 8 | html! {
}; @@ -22,7 +22,7 @@ error: this close tag has no corresponding open tag | = 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-tag-fail.rs:9:13 | 9 | html! {
}; @@ -30,7 +30,7 @@ error: this open tag has no corresponding close tag | = 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-tag-fail.rs:10:24 | 10 | html! {
}; @@ -38,7 +38,7 @@ error: only one root html element allowed | = 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-tag-fail.rs:11:18 | 11 | html! {
}; @@ -46,7 +46,7 @@ error: this close tag has no corresponding open tag | = 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-tag-fail.rs:12:20 | 12 | html! { }; @@ -54,7 +54,7 @@ error: this close tag has no corresponding open tag | = 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-tag-fail.rs:13:18 | 13 | html! {
}; @@ -62,7 +62,7 @@ error: this close tag has no corresponding open tag | = 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-tag-fail.rs:14:20 | 14 | html! { }; @@ -70,7 +70,7 @@ error: only one root html element allowed | = 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-tag-fail.rs:15:18 | 15 | html! {
Invalid
}; @@ -78,7 +78,7 @@ error: expected valid html element | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: only one `attr` attribute allowed +error: the attribute `attr` can only be specified once --> $DIR/html-tag-fail.rs:17:27 | 17 | html! { }; @@ -86,7 +86,7 @@ error: only one `attr` attribute allowed | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: only one `value` attribute allowed +error: the attribute `value` can only be specified once --> $DIR/html-tag-fail.rs:18:32 | 18 | html! { }; @@ -94,7 +94,7 @@ error: only one `value` attribute allowed | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: only one `kind` attribute allowed +error: the attribute `kind` can only be specified once --> $DIR/html-tag-fail.rs:19:36 | 19 | html! { }; @@ -102,7 +102,7 @@ error: only one `kind` attribute allowed | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: only one `checked` attribute allowed +error: the attribute `checked` can only be specified once --> $DIR/html-tag-fail.rs:20:33 | 20 | html! { }; @@ -110,7 +110,7 @@ error: only one `checked` attribute allowed | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: only one `disabled` attribute allowed +error: the attribute `disabled` can only be specified once --> $DIR/html-tag-fail.rs:21:34 | 21 | html! { }; @@ -118,7 +118,7 @@ error: only one `disabled` attribute allowed | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: only one `selected` attribute allowed +error: the attribute `selected` can only be specified once --> $DIR/html-tag-fail.rs:22:35 | 22 | html! {