From 2d652d9d915bec2dabcc911a1cff9e17d16efdfd Mon Sep 17 00:00:00 2001 From: jcamiel Date: Wed, 15 Nov 2023 18:06:32 +0100 Subject: [PATCH] Move runner errors from core.rs to error.rs --- packages/hurl/src/runner/assert.rs | 3 +- packages/hurl/src/runner/body.rs | 2 +- packages/hurl/src/runner/capture.rs | 3 +- packages/hurl/src/runner/core.rs | 106 +------------------- packages/hurl/src/runner/entry.rs | 3 +- packages/hurl/src/runner/error.rs | 106 +++++++++++++++++++- packages/hurl/src/runner/expr.rs | 2 +- packages/hurl/src/runner/json.rs | 4 +- packages/hurl/src/runner/mod.rs | 3 +- packages/hurl/src/runner/multipart.rs | 2 +- packages/hurl/src/runner/predicate.rs | 3 +- packages/hurl/src/runner/predicate_value.rs | 2 +- packages/hurl/src/runner/query.rs | 2 +- packages/hurl/src/runner/request.rs | 4 +- packages/hurl/src/runner/response.rs | 3 +- packages/hurl/src/runner/template.rs | 2 +- 16 files changed, 126 insertions(+), 124 deletions(-) diff --git a/packages/hurl/src/runner/assert.rs b/packages/hurl/src/runner/assert.rs index 9c7fa319ac5..0ad66740307 100644 --- a/packages/hurl/src/runner/assert.rs +++ b/packages/hurl/src/runner/assert.rs @@ -20,7 +20,8 @@ use std::collections::HashMap; use hurl_core::ast::*; use crate::http; -use crate::runner::core::{Error, RunnerError, *}; +use crate::runner::core::AssertResult; +use crate::runner::error::{Error, RunnerError}; use crate::runner::filter::eval_filters; use crate::runner::predicate::eval_predicate; use crate::runner::query::eval_query; diff --git a/packages/hurl/src/runner/body.rs b/packages/hurl/src/runner/body.rs index d8ab7c3f4ba..e8e8b43a622 100644 --- a/packages/hurl/src/runner/body.rs +++ b/packages/hurl/src/runner/body.rs @@ -21,7 +21,7 @@ use std::path::PathBuf; use hurl_core::ast::*; use crate::http; -use crate::runner::core::{Error, RunnerError}; +use crate::runner::error::{Error, RunnerError}; use crate::runner::json::eval_json_value; use crate::runner::multiline::eval_multiline; use crate::runner::template::eval_template; diff --git a/packages/hurl/src/runner/capture.rs b/packages/hurl/src/runner/capture.rs index 34627815cd6..e2b43b08308 100644 --- a/packages/hurl/src/runner/capture.rs +++ b/packages/hurl/src/runner/capture.rs @@ -20,7 +20,8 @@ use std::collections::HashMap; use hurl_core::ast::*; use crate::http; -use crate::runner::core::{CaptureResult, Error, RunnerError}; +use crate::runner::core::CaptureResult; +use crate::runner::error::{Error, RunnerError}; use crate::runner::filter::eval_filters; use crate::runner::query::eval_query; use crate::runner::template::eval_template; diff --git a/packages/hurl/src/runner/core.rs b/packages/hurl/src/runner/core.rs index 17b9c5cda0d..5e39b5888cb 100644 --- a/packages/hurl/src/runner/core.rs +++ b/packages/hurl/src/runner/core.rs @@ -15,12 +15,10 @@ * limitations under the License. * */ -use std::path::PathBuf; - -use hurl_core::ast::SourceInfo; - -use crate::http::{Call, Cookie, RequestedHttpVersion}; +use crate::http::{Call, Cookie}; +use crate::runner::error::Error; use crate::runner::value::Value; +use hurl_core::ast::SourceInfo; #[derive(Clone, Debug, PartialEq, Eq)] pub struct HurlResult { @@ -100,101 +98,3 @@ pub struct CaptureResult { } pub type PredicateResult = Result<(), Error>; - -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct Error { - pub source_info: SourceInfo, - pub inner: RunnerError, - pub assert: bool, -} - -#[derive(Clone, Debug, PartialEq, Eq)] -pub enum RunnerError { - TemplateVariableNotDefined { - name: String, - }, - TemplateVariableInvalidType { - name: String, - value: String, - expecting: String, - }, - InvalidJson { - value: String, - }, - InvalidUrl(String), - InvalidUrlPrefix(String), - - HttpConnection(String), - CouldNotResolveProxyName, - CouldNotResolveHost(String), - FailToConnect, - Timeout, - TooManyRedirect, - CouldNotParseResponse, - SslCertificate(String), - - UnsupportedContentEncoding(String), - UnsupportedHttpVersion(RequestedHttpVersion), - CouldNotUncompressResponse(String), - - FileReadAccess { - value: String, - }, - InvalidDecoding { - charset: String, - }, - InvalidCharset { - charset: String, - }, - - // Query - QueryHeaderNotFound, - QueryCookieNotFound, - QueryInvalidJsonpathExpression { - value: String, - }, - QueryInvalidXpathEval, - QueryInvalidXml, - QueryInvalidJson, - NoQueryResult, - - // Predicate - PredicateType, - PredicateValue(Value), - AssertFailure { - actual: String, - expected: String, - type_mismatch: bool, - }, - InvalidRegex, - - AssertHeaderValueError { - actual: String, - }, - AssertBodyValueError { - actual: String, - expected: String, - }, - AssertVersion { - actual: String, - }, - AssertStatus { - actual: String, - }, - - UnrenderableVariable { - name: String, - value: String, - }, - - UnauthorizedFileAccess { - path: PathBuf, - }, - - // Filter - FilterMissingInput, - FilterInvalidInput(String), - FilterRegexNoCapture, - FilterInvalidEncoding(String), - FilterDecode(String), -} diff --git a/packages/hurl/src/runner/entry.rs b/packages/hurl/src/runner/entry.rs index 16efed96f86..4918d790555 100644 --- a/packages/hurl/src/runner/entry.rs +++ b/packages/hurl/src/runner/entry.rs @@ -22,7 +22,8 @@ use hurl_core::ast::*; use crate::http; use crate::http::ClientOptions; -use crate::runner::core::{Error, RunnerError, *}; +use crate::runner::core::{AssertResult, EntryResult}; +use crate::runner::error::{Error, RunnerError}; use crate::runner::request::{cookie_storage_clear, cookie_storage_set, eval_request}; use crate::runner::response::{eval_asserts, eval_captures, eval_version_status_asserts}; use crate::runner::runner_options::RunnerOptions; diff --git a/packages/hurl/src/runner/error.rs b/packages/hurl/src/runner/error.rs index bb4188da33e..207616c35ee 100644 --- a/packages/hurl/src/runner/error.rs +++ b/packages/hurl/src/runner/error.rs @@ -15,15 +15,111 @@ * limitations under the License. * */ +use crate::http::{HttpError, RequestedHttpVersion}; +use crate::runner::Value; use hurl_core::ast::SourceInfo; -use hurl_core::error::Error; +use std::path::PathBuf; -use crate::http::HttpError; -use crate::runner; -use crate::runner::RunnerError; +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Error { + pub source_info: SourceInfo, + pub inner: RunnerError, + pub assert: bool, +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum RunnerError { + TemplateVariableNotDefined { + name: String, + }, + TemplateVariableInvalidType { + name: String, + value: String, + expecting: String, + }, + InvalidJson { + value: String, + }, + InvalidUrl(String), + InvalidUrlPrefix(String), + + HttpConnection(String), + CouldNotResolveProxyName, + CouldNotResolveHost(String), + FailToConnect, + Timeout, + TooManyRedirect, + CouldNotParseResponse, + SslCertificate(String), + + UnsupportedContentEncoding(String), + UnsupportedHttpVersion(RequestedHttpVersion), + CouldNotUncompressResponse(String), + + FileReadAccess { + value: String, + }, + InvalidDecoding { + charset: String, + }, + InvalidCharset { + charset: String, + }, + + // Query + QueryHeaderNotFound, + QueryCookieNotFound, + QueryInvalidJsonpathExpression { + value: String, + }, + QueryInvalidXpathEval, + QueryInvalidXml, + QueryInvalidJson, + NoQueryResult, + + // Predicate + PredicateType, + PredicateValue(Value), + AssertFailure { + actual: String, + expected: String, + type_mismatch: bool, + }, + InvalidRegex, + + AssertHeaderValueError { + actual: String, + }, + AssertBodyValueError { + actual: String, + expected: String, + }, + AssertVersion { + actual: String, + }, + AssertStatus { + actual: String, + }, + + UnrenderableVariable { + name: String, + value: String, + }, + + UnauthorizedFileAccess { + path: PathBuf, + }, + + // Filter + FilterMissingInput, + FilterInvalidInput(String), + FilterRegexNoCapture, + FilterInvalidEncoding(String), + FilterDecode(String), +} /// Textual Output for runner errors -impl Error for runner::Error { +impl hurl_core::error::Error for Error { fn source_info(&self) -> SourceInfo { self.clone().source_info } diff --git a/packages/hurl/src/runner/expr.rs b/packages/hurl/src/runner/expr.rs index 99623b50d7d..99d7f8efad0 100644 --- a/packages/hurl/src/runner/expr.rs +++ b/packages/hurl/src/runner/expr.rs @@ -19,7 +19,7 @@ use std::collections::HashMap; use hurl_core::ast::Expr; -use crate::runner::core::{Error, RunnerError}; +use crate::runner::error::{Error, RunnerError}; use crate::runner::value::Value; /// Evaluates the expression `expr` with `variables` map and `http_response`, returns a diff --git a/packages/hurl/src/runner/json.rs b/packages/hurl/src/runner/json.rs index 39b798ee9c5..cac60054257 100644 --- a/packages/hurl/src/runner/json.rs +++ b/packages/hurl/src/runner/json.rs @@ -20,7 +20,7 @@ use std::collections::HashMap; use hurl_core::ast::{JsonListElement, JsonObjectElement, JsonValue, Template, TemplateElement}; use hurl_core::parser::{parse_json_boolean, parse_json_null, parse_json_number, Reader}; -use crate::runner::core::{Error, RunnerError}; +use crate::runner::error::{Error, RunnerError}; use crate::runner::template::render_expression; use crate::runner::value::Value; @@ -181,7 +181,7 @@ fn encode_json_char(c: char) -> String { mod tests { use hurl_core::ast::*; - use super::super::core::RunnerError; + use super::super::error::RunnerError; use super::*; pub fn json_hello_world_value() -> JsonValue { diff --git a/packages/hurl/src/runner/mod.rs b/packages/hurl/src/runner/mod.rs index a986956b66e..46ca667540c 100644 --- a/packages/hurl/src/runner/mod.rs +++ b/packages/hurl/src/runner/mod.rs @@ -18,7 +18,8 @@ //! A runner for Hurl files. If you want to execute an Hurl file, this is the right place. -pub use self::core::{AssertResult, CaptureResult, EntryResult, Error, HurlResult, RunnerError}; +pub use self::core::{AssertResult, CaptureResult, EntryResult, HurlResult}; +pub use self::error::{Error, RunnerError}; pub use self::hurl_file::run; pub use self::number::Number; pub use self::runner_options::{RunnerOptions, RunnerOptionsBuilder}; diff --git a/packages/hurl/src/runner/multipart.rs b/packages/hurl/src/runner/multipart.rs index 471f6258733..6a2e4954402 100644 --- a/packages/hurl/src/runner/multipart.rs +++ b/packages/hurl/src/runner/multipart.rs @@ -23,7 +23,7 @@ use hurl_core::ast::*; use crate::http; use crate::runner::body::eval_file; -use crate::runner::core::Error; +use crate::runner::error::Error; use crate::runner::template::eval_template; use crate::runner::value::Value; use crate::util::path::ContextDir; diff --git a/packages/hurl/src/runner/predicate.rs b/packages/hurl/src/runner/predicate.rs index f8594e834df..5764ed1a920 100644 --- a/packages/hurl/src/runner/predicate.rs +++ b/packages/hurl/src/runner/predicate.rs @@ -21,7 +21,8 @@ use std::collections::HashMap; use hurl_core::ast::*; use regex; -use crate::runner::core::{Error, PredicateResult}; +use crate::runner::core::PredicateResult; +use crate::runner::error::Error; use crate::runner::predicate_value::{eval_predicate_value, eval_predicate_value_template}; use crate::runner::template::eval_template; use crate::runner::value::Value; diff --git a/packages/hurl/src/runner/predicate_value.rs b/packages/hurl/src/runner/predicate_value.rs index 33cda66592c..395d61b648f 100644 --- a/packages/hurl/src/runner/predicate_value.rs +++ b/packages/hurl/src/runner/predicate_value.rs @@ -19,7 +19,7 @@ use std::collections::HashMap; use hurl_core::ast::*; -use crate::runner::core::Error; +use crate::runner::error::Error; use crate::runner::expr::eval_expr; use crate::runner::multiline::eval_multiline; use crate::runner::template::eval_template; diff --git a/packages/hurl/src/runner/query.rs b/packages/hurl/src/runner/query.rs index 142dfeb44e7..48e0bb898c7 100644 --- a/packages/hurl/src/runner/query.rs +++ b/packages/hurl/src/runner/query.rs @@ -21,7 +21,7 @@ use hurl_core::ast::*; use regex::Regex; use sha2::Digest; -use crate::runner::core::{Error, RunnerError}; +use crate::runner::error::{Error, RunnerError}; use crate::runner::filter; use crate::runner::template::eval_template; use crate::runner::Number; diff --git a/packages/hurl/src/runner/request.rs b/packages/hurl/src/runner/request.rs index abbe8f7e8ed..eaa6f9fe0c6 100644 --- a/packages/hurl/src/runner/request.rs +++ b/packages/hurl/src/runner/request.rs @@ -23,7 +23,7 @@ use hurl_core::ast::*; use crate::http; use crate::runner::body::eval_body; -use crate::runner::core::Error; +use crate::runner::error::Error; use crate::runner::multipart::eval_multipart_param; use crate::runner::template::eval_template; use crate::runner::value::Value; @@ -169,7 +169,7 @@ fn eval_method(method: &Method) -> http::Method { mod tests { use hurl_core::ast::SourceInfo; - use super::super::core::RunnerError; + use super::super::error::RunnerError; use super::*; fn whitespace() -> Whitespace { diff --git a/packages/hurl/src/runner/response.rs b/packages/hurl/src/runner/response.rs index 9a0cbc880af..995f3630ff2 100644 --- a/packages/hurl/src/runner/response.rs +++ b/packages/hurl/src/runner/response.rs @@ -23,7 +23,8 @@ use crate::http; use crate::runner::assert::eval_assert; use crate::runner::body::eval_body; use crate::runner::capture::eval_capture; -use crate::runner::core::*; +use crate::runner::core::{AssertResult, CaptureResult}; +use crate::runner::error::{Error, RunnerError}; use crate::runner::json::eval_json_value; use crate::runner::multiline::eval_multiline; use crate::runner::template::eval_template; diff --git a/packages/hurl/src/runner/template.rs b/packages/hurl/src/runner/template.rs index 33b6aff0503..04295ab6f71 100644 --- a/packages/hurl/src/runner/template.rs +++ b/packages/hurl/src/runner/template.rs @@ -19,7 +19,7 @@ use std::collections::HashMap; use hurl_core::ast::*; -use crate::runner::core::{Error, RunnerError}; +use crate::runner::error::{Error, RunnerError}; use crate::runner::Value; /// Renders to string a `template` given a map of variables.