Skip to content

Commit

Permalink
Move runner errors from core.rs to error.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
jcamiel committed Nov 15, 2023
1 parent f22e428 commit 2d652d9
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 124 deletions.
3 changes: 2 additions & 1 deletion packages/hurl/src/runner/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/hurl/src/runner/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion packages/hurl/src/runner/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
106 changes: 3 additions & 103 deletions packages/hurl/src/runner/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
}
3 changes: 2 additions & 1 deletion packages/hurl/src/runner/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
106 changes: 101 additions & 5 deletions packages/hurl/src/runner/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion packages/hurl/src/runner/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/hurl/src/runner/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion packages/hurl/src/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion packages/hurl/src/runner/multipart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion packages/hurl/src/runner/predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/hurl/src/runner/predicate_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/hurl/src/runner/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/hurl/src/runner/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion packages/hurl/src/runner/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/hurl/src/runner/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 2d652d9

Please sign in to comment.