Skip to content

Commit

Permalink
Fix parse error messages
Browse files Browse the repository at this point in the history
* Previously some types would .unwrap() which causes ugly `unwrap` error message to be shown which would clutter the actual error message. Use
the `?` to fail gracefully and return the actual error message.
  • Loading branch information
juhaku committed Apr 4, 2022
1 parent 7a5a945 commit 0c43bff
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions utoipa-gen/src/component/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Parse for ComponentAttr<Enum> {
}

if !input.is_empty() {
input.parse::<Token![,]>().unwrap();
input.parse::<Token![,]>()?;
}
}
Ok(Self { inner: enum_attr })
Expand Down Expand Up @@ -152,7 +152,7 @@ impl Parse for ComponentAttr<Struct> {
}

if !input.is_empty() {
input.parse::<Token![,]>().unwrap();
input.parse::<Token![,]>()?;
}
}

Expand Down Expand Up @@ -190,7 +190,7 @@ impl Parse for ComponentAttr<UnnamedFieldStruct> {
}

if !input.is_empty() {
input.parse::<Token![,]>().unwrap();
input.parse::<Token![,]>()?;
}
}

Expand Down Expand Up @@ -291,7 +291,7 @@ impl Parse for ComponentAttr<NamedField> {
}

if !input.is_empty() {
input.parse::<Token![,]>().unwrap();
input.parse::<Token![,]>()?;
}
}

Expand Down
2 changes: 1 addition & 1 deletion utoipa-gen/src/component/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Parse for XmlAttr {
}

if !input.is_empty() {
input.parse::<Token![,]>().unwrap();
input.parse::<Token![,]>()?;
}
}

Expand Down
2 changes: 1 addition & 1 deletion utoipa-gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ impl Parse for ExternalDocs {
}

if !input.is_empty() {
input.parse::<Token![,]>().unwrap();
input.parse::<Token![,]>()?;
}
}

Expand Down
4 changes: 2 additions & 2 deletions utoipa-gen/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl Parse for OpenApiAttr {
}

if !input.is_empty() {
input.parse::<Token![,]>().unwrap_or_abort();
input.parse::<Token![,]>()?;
}
}

Expand Down Expand Up @@ -171,7 +171,7 @@ impl Parse for Tag {
}

if !input.is_empty() {
input.parse::<Token![,]>().unwrap();
input.parse::<Token![,]>()?;
}
}

Expand Down
2 changes: 1 addition & 1 deletion utoipa-gen/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl Parse for PathAttr {
}

if !input.is_empty() {
input.parse::<Token![,]>().unwrap();
input.parse::<Token![,]>()?;
}
}

Expand Down

0 comments on commit 0c43bff

Please sign in to comment.