Combine InvalidUrl RunnerError

This commit is contained in:
Fabrice Reix 2024-04-17 14:16:17 +02:00
parent d72d3ebb12
commit 01ce239f54
No known key found for this signature in database
GPG Key ID: BF5213154B2E7155
7 changed files with 86 additions and 71 deletions

View File

@ -2,6 +2,6 @@ error: Invalid URL
--> tests_failed/invalid_url_1.hurl:3:5
|
3 | GET {{host}}
| ^^^^^^^^ URL <localhost:8000> must start with http:// or https://
| ^^^^^^^^ invalid URL <localhost:8000> (Missing protocol http or https)
|

View File

@ -139,114 +139,121 @@ error: Invalid regex
| ^^^^ regex expression is not valid
|
error: Invalid URL
--> tests_failed/runner_errors.hurl:94:5
|
94 | GET {{url}}
| ^^^^^^^ invalid URL <localhost:8000/runner_errors> (Missing protocol http or https)
|
error: No query result
--> tests_failed/runner_errors.hurl:103:8
--> tests_failed/runner_errors.hurl:102:8
|
| GET http://localhost:8000/runner_errors
| ...
103 | count: header "count"
102 | count: header "count"
| ^^^^^^^^^^^^^^ The query didn't return any result
|
error: Header not found
--> tests_failed/runner_errors.hurl:108:1
--> tests_failed/runner_errors.hurl:107:1
|
| GET http://localhost:8000/runner_errors
| ...
108 | count: 10
107 | count: 10
| ^^^^^ this header has not been found in the response
|
error: Invalid JSON
--> tests_failed/runner_errors.hurl:114:1
--> tests_failed/runner_errors.hurl:113:1
|
| GET http://localhost:8000/runner_errors
| ...
114 | jsonpath "$.count" == 10
113 | jsonpath "$.count" == 10
| ^^^^^^^^^^^^^^^^^^ the HTTP response is not a valid JSON
|
error: Invalid JSONPath
--> tests_failed/runner_errors.hurl:120:10
--> tests_failed/runner_errors.hurl:119:10
|
| GET http://localhost:8000/runner_errors
| ...
120 | jsonpath "xxx" == 10
119 | jsonpath "xxx" == 10
| ^^^^^ the JSONPath expression 'xxx' is not valid
|
error: Invalid XML
--> tests_failed/runner_errors.hurl:126:1
--> tests_failed/runner_errors.hurl:125:1
|
| GET http://localhost:8000/runner_errors/invalid-xml
| ...
126 | xpath "//a" == 10
125 | xpath "//a" == 10
| ^^^^^^^^^^^ the HTTP response is not a valid XML
|
error: Invalid XPath expression
--> tests_failed/runner_errors.hurl:132:7
--> tests_failed/runner_errors.hurl:131:7
|
| GET http://localhost:8000/runner_errors
| ...
132 | xpath "//" == 10
131 | xpath "//" == 10
| ^^^^ the XPath expression is not valid
|
error: Invalid variable type
--> tests_failed/runner_errors.hurl:138:12
--> tests_failed/runner_errors.hurl:137:12
|
| GET http://localhost:8000/runner_errors
| ...
138 | verbose: {{verbose}}
137 | verbose: {{verbose}}
| ^^^^^^^ expecting boolean, actual value is <1>
|
error: Undefined variable
--> tests_failed/runner_errors.hurl:143:10
--> tests_failed/runner_errors.hurl:142:10
|
| GET http://localhost:8000/runner_errors
| ...
143 | param: {{value}}
142 | param: {{value}}
| ^^^^^ you must set the variable value
|
error: HTTP connection
--> tests_failed/runner_errors.hurl:146:5
--> tests_failed/runner_errors.hurl:145:5
|
146 | GET http://localhost:8000/runner_errors/redirect/2
145 | GET http://localhost:8000/runner_errors/redirect/2
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ too many redirect
|
error: Unauthorized file access
--> tests_failed/runner_errors.hurl:153:6
--> tests_failed/runner_errors.hurl:152:6
|
| GET http://localhost:8000/runner_errors
153 | file,/root/file;
152 | file,/root/file;
| ^^^^^^^^^^ unauthorized access to file /root/file, check --file-root option
|
error: Unrenderable variable
--> tests_failed/runner_errors.hurl:161:4
--> tests_failed/runner_errors.hurl:160:4
|
| GET http://localhost:8000/runner_errors
161 | `{{list}}`
160 | `{{list}}`
| ^^^^ variable <list> with value [1,2,3] can not be rendered
|
error: Decompression error
--> tests_failed/runner_errors.hurl:167:1
--> tests_failed/runner_errors.hurl:166:1
|
| GET http://localhost:8000/runner_errors/unsupported-content-encoding
| ...
167 | bytes count == 10
166 | bytes count == 10
| ^^^^^ compression unknown is not supported
|
error: Unsupported HTTP version
--> tests_failed/runner_errors.hurl:170:5
--> tests_failed/runner_errors.hurl:169:5
|
170 | GET http://localhost:8000/runner_errors
169 | GET http://localhost:8000/runner_errors
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ HTTP/3 is not supported, check --version
|

View File

@ -91,10 +91,9 @@ HTTP 200
body regex "{}" == "a"
# InvalidUrl
#GET http:///
# InvalidUrlPrefix
# TODO: remove enum variant if not used
GET {{url}}
[Options]
variable: url=localhost:8000/runner_errors
# NoQueryResult
GET http://localhost:8000/runner_errors

View File

@ -139,114 +139,121 @@
 | ^^^^ regex expression is not valid
 |
error: Invalid URL
--> tests_failed/runner_errors.hurl:94:5
 |
 94 | GET {{url}}
 | ^^^^^^^ invalid URL <localhost:8000/runner_errors> (Missing protocol http or https)
 |
error: No query result
--> tests_failed/runner_errors.hurl:103:8
--> tests_failed/runner_errors.hurl:102:8
 |
 | GET http://localhost:8000/runner_errors
 | ...
103 | count: header "count"
102 | count: header "count"
 | ^^^^^^^^^^^^^^ The query didn't return any result
 |
error: Header not found
--> tests_failed/runner_errors.hurl:108:1
--> tests_failed/runner_errors.hurl:107:1
 |
 | GET http://localhost:8000/runner_errors
 | ...
108 | count: 10
107 | count: 10
 | ^^^^^ this header has not been found in the response
 |
error: Invalid JSON
--> tests_failed/runner_errors.hurl:114:1
--> tests_failed/runner_errors.hurl:113:1
 |
 | GET http://localhost:8000/runner_errors
 | ...
114 | jsonpath "$.count" == 10
113 | jsonpath "$.count" == 10
 | ^^^^^^^^^^^^^^^^^^ the HTTP response is not a valid JSON
 |
error: Invalid JSONPath
--> tests_failed/runner_errors.hurl:120:10
--> tests_failed/runner_errors.hurl:119:10
 |
 | GET http://localhost:8000/runner_errors
 | ...
120 | jsonpath "xxx" == 10
119 | jsonpath "xxx" == 10
 | ^^^^^ the JSONPath expression 'xxx' is not valid
 |
error: Invalid XML
--> tests_failed/runner_errors.hurl:126:1
--> tests_failed/runner_errors.hurl:125:1
 |
 | GET http://localhost:8000/runner_errors/invalid-xml
 | ...
126 | xpath "//a" == 10
125 | xpath "//a" == 10
 | ^^^^^^^^^^^ the HTTP response is not a valid XML
 |
error: Invalid XPath expression
--> tests_failed/runner_errors.hurl:132:7
--> tests_failed/runner_errors.hurl:131:7
 |
 | GET http://localhost:8000/runner_errors
 | ...
132 | xpath "//" == 10
131 | xpath "//" == 10
 | ^^^^ the XPath expression is not valid
 |
error: Invalid variable type
--> tests_failed/runner_errors.hurl:138:12
--> tests_failed/runner_errors.hurl:137:12
 |
 | GET http://localhost:8000/runner_errors
 | ...
138 | verbose: {{verbose}}
137 | verbose: {{verbose}}
 | ^^^^^^^ expecting boolean, actual value is <1>
 |
error: Undefined variable
--> tests_failed/runner_errors.hurl:143:10
--> tests_failed/runner_errors.hurl:142:10
 |
 | GET http://localhost:8000/runner_errors
 | ...
143 | param: {{value}}
142 | param: {{value}}
 | ^^^^^ you must set the variable value
 |
error: HTTP connection
--> tests_failed/runner_errors.hurl:146:5
--> tests_failed/runner_errors.hurl:145:5
 |
146 | GET http://localhost:8000/runner_errors/redirect/2
145 | GET http://localhost:8000/runner_errors/redirect/2
 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ too many redirect
 |
error: Unauthorized file access
--> tests_failed/runner_errors.hurl:153:6
--> tests_failed/runner_errors.hurl:152:6
 |
 | GET http://localhost:8000/runner_errors
153 | file,/root/file;
152 | file,/root/file;
 | ^^^^^^^^^^ unauthorized access to file /root/file, check --file-root option
 |
error: Unrenderable variable
--> tests_failed/runner_errors.hurl:161:4
--> tests_failed/runner_errors.hurl:160:4
 |
 | GET http://localhost:8000/runner_errors
161 | `{{list}}`
160 | `{{list}}`
 | ^^^^ variable <list> with value [1,2,3] can not be rendered
 |
error: Decompression error
--> tests_failed/runner_errors.hurl:167:1
--> tests_failed/runner_errors.hurl:166:1
 |
 | GET http://localhost:8000/runner_errors/unsupported-content-encoding
 | ...
167 | bytes count == 10
166 | bytes count == 10
 | ^^^^^ compression unknown is not supported
 |
error: Unsupported HTTP version
--> tests_failed/runner_errors.hurl:170:5
--> tests_failed/runner_errors.hurl:169:5
 |
170 | GET http://localhost:8000/runner_errors
169 | GET http://localhost:8000/runner_errors
 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ HTTP/3 is not supported, check --version
 |

View File

@ -44,8 +44,7 @@ pub enum HttpError {
description: String,
},
UnsupportedHttpVersion(RequestedHttpVersion),
InvalidUrl(String),
InvalidUrlPrefix(String),
InvalidUrl(String, String),
}
impl From<curl::Error> for HttpError {

View File

@ -108,15 +108,23 @@ impl Request {
// FIXME: is it possible to do it with libcurl?
let url = match Url::parse(&self.url) {
Ok(url) => url,
Err(_) => return Err(HttpError::InvalidUrl(self.url.clone())),
Err(e) => return Err(HttpError::InvalidUrl(self.url.clone(), e.to_string())),
};
let scheme = url.scheme();
if scheme != "http" && scheme != "https" {
return Err(HttpError::InvalidUrlPrefix(self.url.clone()));
return Err(HttpError::InvalidUrl(
self.url.clone(),
"Missing protocol http or https".to_string(),
));
}
let host = match url.host() {
Some(host) => host,
None => return Err(HttpError::InvalidUrl(self.url.clone())),
None => {
return Err(HttpError::InvalidUrl(
self.url.clone(),
"Can not extract host".to_string(),
))
}
};
let port = match url.port() {
Some(port) => format!(":{port}"),

View File

@ -87,8 +87,7 @@ pub enum RunnerError {
charset: String,
},
InvalidRegex,
InvalidUrl(String),
InvalidUrlPrefix(String),
InvalidUrl(String, String),
NoQueryResult,
QueryHeaderNotFound,
QueryInvalidJsonpathExpression {
@ -144,7 +143,6 @@ impl hurl_core::error::Error for Error {
RunnerError::InvalidJson { .. } => "Invalid JSON".to_string(),
RunnerError::InvalidRegex => "Invalid regex".to_string(),
RunnerError::InvalidUrl(..) => "Invalid URL".to_string(),
RunnerError::InvalidUrlPrefix(..) => "Invalid URL".to_string(),
RunnerError::NoQueryResult => "No query result".to_string(),
RunnerError::QueryHeaderNotFound => "Header not found".to_string(),
RunnerError::QueryInvalidJson => "Invalid JSON".to_string(),
@ -214,10 +212,8 @@ impl hurl_core::error::Error for Error {
format!("actual value is <{value}>")
}
RunnerError::InvalidRegex => "regex expression is not valid".to_string(),
RunnerError::InvalidUrl(url) => format!("invalid URL <{url}>"),
RunnerError::InvalidUrlPrefix(url) => {
format!("URL <{url}> must start with http:// or https://")
}
RunnerError::InvalidUrl(url, reason) => format!("invalid URL <{url}> ({reason})"),
RunnerError::NoQueryResult => "The query didn't return any result".to_string(),
RunnerError::QueryHeaderNotFound => {
"this header has not been found in the response".to_string()
@ -276,8 +272,7 @@ impl From<HttpError> for RunnerError {
}
HttpError::InvalidCharset { charset } => RunnerError::InvalidCharset { charset },
HttpError::InvalidDecoding { charset } => RunnerError::InvalidDecoding { charset },
HttpError::InvalidUrl(url) => RunnerError::InvalidUrl(url),
HttpError::InvalidUrlPrefix(url) => RunnerError::InvalidUrlPrefix(url),
HttpError::InvalidUrl(url, reason) => RunnerError::InvalidUrl(url, reason),
HttpError::Libcurl { code, description } => {
RunnerError::HttpConnection(format!("({code}) {description}"))
}