Rename inner variable to kind.

This commit is contained in:
Jean-Christophe Amiel 2024-05-15 22:10:40 +02:00
parent b3756fe1f1
commit 81129ee818
No known key found for this signature in database
GPG Key ID: 07FF11CFD55356CC
44 changed files with 203 additions and 205 deletions

View File

@ -43,10 +43,10 @@ impl AssertResult {
{
None
} else {
let inner = RunnerErrorKind::AssertVersion {
let kind = RunnerErrorKind::AssertVersion {
actual: actual.to_string(),
};
Some(RunnerError::new(*source_info, inner, false))
Some(RunnerError::new(*source_info, kind, false))
}
}
AssertResult::Status {
@ -57,10 +57,10 @@ impl AssertResult {
if actual == expected {
None
} else {
let inner = RunnerErrorKind::AssertStatus {
let kind = RunnerErrorKind::AssertStatus {
actual: actual.to_string(),
};
Some(RunnerError::new(*source_info, inner, false))
Some(RunnerError::new(*source_info, kind, false))
}
}
AssertResult::Header {
@ -73,8 +73,8 @@ impl AssertResult {
if s == expected {
None
} else {
let inner = RunnerErrorKind::AssertHeaderValueError { actual: s.clone() };
Some(RunnerError::new(*source_info, inner, false))
let kind = RunnerErrorKind::AssertHeaderValueError { actual: s.clone() };
Some(RunnerError::new(*source_info, kind, false))
}
}
},
@ -92,8 +92,8 @@ impl AssertResult {
} else {
let actual = actual.to_string();
let expected = expected.to_string();
let inner = RunnerErrorKind::AssertBodyValueError { actual, expected };
Some(RunnerError::new(*source_info, inner, false))
let kind = RunnerErrorKind::AssertBodyValueError { actual, expected };
Some(RunnerError::new(*source_info, kind, false))
}
}
},

View File

@ -75,15 +75,15 @@ pub fn eval_file(
// is a child of the context directory.
let path = PathBuf::from(file);
if !context_dir.is_access_allowed(&path) {
let inner = RunnerErrorKind::UnauthorizedFileAccess { path };
return Err(RunnerError::new(filename.source_info, inner, false));
let kind = RunnerErrorKind::UnauthorizedFileAccess { path };
return Err(RunnerError::new(filename.source_info, kind, false));
}
let resolved_file = context_dir.resolved_path(&path);
match std::fs::read(resolved_file) {
Ok(value) => Ok(value),
Err(_) => {
let inner = RunnerErrorKind::FileReadAccess { path };
Err(RunnerError::new(filename.source_info, inner, false))
let kind = RunnerErrorKind::FileReadAccess { path };
Err(RunnerError::new(filename.source_info, kind, false))
}
}
}

View File

@ -35,10 +35,10 @@ pub struct RunnerError {
}
impl RunnerError {
pub fn new(source_info: SourceInfo, inner: RunnerErrorKind, assert: bool) -> RunnerError {
pub fn new(source_info: SourceInfo, kind: RunnerErrorKind, assert: bool) -> RunnerError {
RunnerError {
source_info,
kind: inner,
kind,
assert,
}
}

View File

@ -28,9 +28,9 @@ pub fn eval_expr(expr: &Expr, variables: &HashMap<String, Value>) -> Result<Valu
if let Some(value) = variables.get(expr.variable.name.as_str()) {
Ok(value.clone())
} else {
let inner = RunnerErrorKind::TemplateVariableNotDefined {
let kind = RunnerErrorKind::TemplateVariableNotDefined {
name: expr.variable.name.clone(),
};
Err(RunnerError::new(expr.variable.source_info, inner, false))
Err(RunnerError::new(expr.variable.source_info, kind, false))
}
}

View File

@ -30,8 +30,8 @@ pub fn eval_count(
Value::Bytes(values) => Ok(Some(Value::Number(Number::Integer(values.len() as i64)))),
Value::Nodeset(size) => Ok(Some(Value::Number(Number::Integer(*size as i64)))),
v => {
let inner = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, kind, assert))
}
}
}

View File

@ -33,8 +33,8 @@ pub fn eval_days_after_now(
Ok(Some(Value::Number(Number::Integer(diff.num_days()))))
}
v => {
let inner = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, kind, assert))
}
}
}

View File

@ -33,8 +33,8 @@ pub fn eval_days_before_now(
Ok(Some(Value::Number(Number::Integer(diff.num_days()))))
}
v => {
let inner = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, kind, assert))
}
}
}

View File

@ -35,21 +35,21 @@ pub fn eval_decode(
Value::Bytes(value) => {
match encoding::label::encoding_from_whatwg_label(encoding_value.as_str()) {
None => {
let inner = RunnerErrorKind::FilterInvalidEncoding(encoding_value);
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidEncoding(encoding_value);
Err(RunnerError::new(source_info, kind, assert))
}
Some(enc) => match enc.decode(value, DecoderTrap::Strict) {
Ok(decoded) => Ok(Some(Value::String(decoded))),
Err(_) => {
let inner = RunnerErrorKind::FilterDecode(encoding_value);
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterDecode(encoding_value);
Err(RunnerError::new(source_info, kind, assert))
}
},
}
}
v => {
let inner = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, kind, assert))
}
}
}

View File

@ -37,8 +37,8 @@ pub fn eval_format(
Ok(Some(Value::String(formatted)))
}
v => {
let inner = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, kind, assert))
}
}
}

View File

@ -32,8 +32,8 @@ pub fn eval_html_escape(
Ok(Some(Value::String(encoded)))
}
v => {
let inner = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, kind, assert))
}
}
}

View File

@ -32,8 +32,8 @@ pub fn eval_html_unescape(
Ok(Some(Value::String(decoded)))
}
v => {
let inner = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, kind, assert))
}
}
}

View File

@ -33,8 +33,8 @@ pub fn eval_jsonpath(
match value {
Value::String(json) => eval_jsonpath_string(json, expr, variables, source_info),
v => {
let inner = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, kind, assert))
}
}
}
@ -50,8 +50,8 @@ pub fn eval_jsonpath_string(
let jsonpath_query = match jsonpath::parse(value.as_str()) {
Ok(q) => q,
Err(_) => {
let inner = RunnerErrorKind::QueryInvalidJsonpathExpression { value };
return Err(RunnerError::new(*expr_source_info, inner, false));
let kind = RunnerErrorKind::QueryInvalidJsonpathExpression { value };
return Err(RunnerError::new(*expr_source_info, kind, false));
}
};
let value = match serde_json::from_str(json) {

View File

@ -29,17 +29,17 @@ pub fn eval_nth(
match value {
Value::List(values) => match values.get(n as usize) {
None => {
let inner = RunnerErrorKind::FilterInvalidInput(format!(
let kind = RunnerErrorKind::FilterInvalidInput(format!(
"Out of bound - size is {}",
values.len()
));
Err(RunnerError::new(source_info, inner, assert))
Err(RunnerError::new(source_info, kind, assert))
}
Some(value) => Ok(Some(value.clone())),
},
v => {
let inner = RunnerErrorKind::FilterInvalidInput(v.display());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(v.display());
Err(RunnerError::new(source_info, kind, assert))
}
}
}

View File

@ -40,8 +40,8 @@ pub fn eval_regex(
None => Ok(None),
},
v => {
let inner = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, kind, assert))
}
}
}

View File

@ -39,8 +39,8 @@ pub fn eval_replace(
Ok(Some(Value::String(s)))
}
v => {
let inner = RunnerErrorKind::FilterInvalidInput(v.display());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(v.display());
Err(RunnerError::new(source_info, kind, assert))
}
}
}

View File

@ -39,8 +39,8 @@ pub fn eval_split(
Ok(Some(Value::List(values)))
}
v => {
let inner = RunnerErrorKind::FilterInvalidInput(v.display());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(v.display());
Err(RunnerError::new(source_info, kind, assert))
}
}
}

View File

@ -39,13 +39,13 @@ pub fn eval_to_date(
v.and_local_timezone(chrono::Utc).unwrap(),
))),
Err(_) => {
let inner = RunnerErrorKind::FilterInvalidInput(value.display());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(value.display());
Err(RunnerError::new(source_info, kind, assert))
}
},
v => {
let inner = RunnerErrorKind::FilterInvalidInput(v.display());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(v.display());
Err(RunnerError::new(source_info, kind, assert))
}
}
}

View File

@ -30,13 +30,13 @@ pub fn eval_to_float(
Value::String(v) => match v.parse::<f64>() {
Ok(f) => Ok(Some(Value::Number(Number::Float(f)))),
_ => {
let inner = RunnerErrorKind::FilterInvalidInput(value.display());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(value.display());
Err(RunnerError::new(source_info, kind, assert))
}
},
v => {
let inner = RunnerErrorKind::FilterInvalidInput(v.display());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(v.display());
Err(RunnerError::new(source_info, kind, assert))
}
}
}

View File

@ -31,13 +31,13 @@ pub fn eval_to_int(
Value::String(v) => match v.parse::<i64>() {
Ok(i) => Ok(Some(Value::Number(Number::Integer(i)))),
_ => {
let inner = RunnerErrorKind::FilterInvalidInput(value.display());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(value.display());
Err(RunnerError::new(source_info, kind, assert))
}
},
v => {
let inner = RunnerErrorKind::FilterInvalidInput(v.display());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(v.display());
Err(RunnerError::new(source_info, kind, assert))
}
}
}

View File

@ -30,15 +30,15 @@ pub fn eval_url_decode(
match percent_encoding::percent_decode(value.as_bytes()).decode_utf8() {
Ok(decoded) => Ok(Some(Value::String(decoded.to_string()))),
Err(_) => {
let inner =
let kind =
RunnerErrorKind::FilterInvalidInput("Invalid UTF-8 stream".to_string());
Err(RunnerError::new(source_info, inner, assert))
Err(RunnerError::new(source_info, kind, assert))
}
}
}
v => {
let inner = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, kind, assert))
}
}
}

View File

@ -40,8 +40,8 @@ pub fn eval_url_encode(
Ok(Some(Value::String(encoded)))
}
v => {
let inner = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, kind, assert))
}
}
}

View File

@ -36,8 +36,8 @@ pub fn eval_xpath(
eval_xpath_string(xml, expr, variables, source_info, is_html)
}
v => {
let inner = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, inner, assert))
let kind = RunnerErrorKind::FilterInvalidInput(v._type());
Err(RunnerError::new(source_info, kind, assert))
}
}
}

View File

@ -82,8 +82,8 @@ pub fn eval_json_value(
if parse_json_null(&mut reader).is_ok() {
return Ok(s);
}
let inner = RunnerErrorKind::InvalidJson { value: s };
Err(RunnerError::new(exp.variable.source_info, inner, false))
let kind = RunnerErrorKind::InvalidJson { value: s };
Err(RunnerError::new(exp.variable.source_info, kind, false))
}
}
}

View File

@ -304,12 +304,12 @@ fn eval_boolean_option(
BooleanOption::Expression(expr) => match eval_expression(expr, variables)? {
Value::Bool(value) => Ok(value),
v => {
let inner = RunnerErrorKind::TemplateVariableInvalidType {
let kind = RunnerErrorKind::TemplateVariableInvalidType {
name: expr.variable.name.clone(),
value: v.to_string(),
expecting: "boolean".to_string(),
};
Err(RunnerError::new(expr.variable.source_info, inner, false))
Err(RunnerError::new(expr.variable.source_info, kind, false))
}
},
}
@ -324,23 +324,23 @@ fn eval_natural_option(
NaturalOption::Expression(expr) => match eval_expression(expr, variables)? {
Value::Number(Number::Integer(value)) => {
if value < 0 {
let inner = RunnerErrorKind::TemplateVariableInvalidType {
let kind = RunnerErrorKind::TemplateVariableInvalidType {
name: expr.variable.name.clone(),
value: value.to_string(),
expecting: "positive integer".to_string(),
};
Err(RunnerError::new(expr.variable.source_info, inner, false))
Err(RunnerError::new(expr.variable.source_info, kind, false))
} else {
Ok(value as u64)
}
}
v => {
let inner = RunnerErrorKind::TemplateVariableInvalidType {
let kind = RunnerErrorKind::TemplateVariableInvalidType {
name: expr.variable.name.clone(),
value: v.to_string(),
expecting: "positive integer".to_string(),
};
Err(RunnerError::new(expr.variable.source_info, inner, false))
Err(RunnerError::new(expr.variable.source_info, kind, false))
}
},
}
@ -361,21 +361,21 @@ fn eval_retry_option(
} else if value > 0 {
Ok(Retry::Finite(value as usize))
} else {
let inner = RunnerErrorKind::TemplateVariableInvalidType {
let kind = RunnerErrorKind::TemplateVariableInvalidType {
name: expr.variable.name.clone(),
value: value.to_string(),
expecting: "integer".to_string(),
};
Err(RunnerError::new(expr.variable.source_info, inner, false))
Err(RunnerError::new(expr.variable.source_info, kind, false))
}
}
v => {
let inner = RunnerErrorKind::TemplateVariableInvalidType {
let kind = RunnerErrorKind::TemplateVariableInvalidType {
name: expr.variable.name.clone(),
value: v.to_string(),
expecting: "integer".to_string(),
};
Err(RunnerError::new(expr.variable.source_info, inner, false))
Err(RunnerError::new(expr.variable.source_info, kind, false))
}
},
}

View File

@ -112,18 +112,18 @@ impl RunnerError {
fn new_file_write_access(path: &Path, error: &str) -> RunnerError {
let source_info = SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0));
let path = path.to_path_buf();
let inner = RunnerErrorKind::FileWriteAccess {
let kind = RunnerErrorKind::FileWriteAccess {
path,
error: error.to_string(),
};
RunnerError::new(source_info, inner, false)
RunnerError::new(source_info, kind, false)
}
/// Creates a new authorization access error.
fn new_unauthorized_file_access(path: &Path) -> RunnerError {
let source_info = SourceInfo::new(Pos::new(0, 0), Pos::new(0, 0));
let path = path.to_path_buf();
let inner = RunnerErrorKind::UnauthorizedFileAccess { path };
RunnerError::new(source_info, inner, false)
let kind = RunnerErrorKind::UnauthorizedFileAccess { path };
RunnerError::new(source_info, kind, false)
}
}

View File

@ -68,26 +68,26 @@ pub fn eval_predicate(
if assert_result.type_mismatch {
let not = if predicate.not { "not " } else { "" };
let expected = format!("{}{}", not, assert_result.expected);
let inner = RunnerErrorKind::AssertFailure {
let kind = RunnerErrorKind::AssertFailure {
actual: assert_result.actual,
expected,
type_mismatch: true,
};
Err(RunnerError::new(source_info, inner, true))
Err(RunnerError::new(source_info, kind, true))
} else if predicate.not && assert_result.success {
let inner = RunnerErrorKind::AssertFailure {
let kind = RunnerErrorKind::AssertFailure {
actual: assert_result.actual,
expected: format!("not {}", assert_result.expected),
type_mismatch: false,
};
Err(RunnerError::new(source_info, inner, true))
Err(RunnerError::new(source_info, kind, true))
} else if !predicate.not && !assert_result.success {
let inner = RunnerErrorKind::AssertFailure {
let kind = RunnerErrorKind::AssertFailure {
actual: assert_result.actual,
expected: assert_result.expected,
type_mismatch: false,
};
Err(RunnerError::new(source_info, inner, true))
Err(RunnerError::new(source_info, kind, true))
} else {
Ok(())
}

View File

@ -58,11 +58,11 @@ pub fn render_expression(
if value.is_renderable() {
Ok(value.to_string())
} else {
let inner = RunnerErrorKind::UnrenderableVariable {
let kind = RunnerErrorKind::UnrenderableVariable {
name: name.to_string(),
value: value.to_string(),
};
Err(RunnerError::new(source_info, inner, false))
Err(RunnerError::new(source_info, kind, false))
}
}
@ -75,8 +75,8 @@ pub fn eval_expression(
match variables.get(name.as_str()) {
Some(value) => Ok(value.clone()),
_ => {
let inner = RunnerErrorKind::TemplateVariableNotDefined { name: name.clone() };
Err(RunnerError::new(source_info, inner, false))
let kind = RunnerErrorKind::TemplateVariableNotDefined { name: name.clone() };
Err(RunnerError::new(source_info, kind, false))
}
}
}

View File

@ -556,11 +556,11 @@ pub mod tests {
fn test_error_timeout() {
let content = "GET http://unknown";
let filename = "test.hurl";
let inner =
let kind =
RunnerErrorKind::HttpConnection("(6) Could not resolve host: unknown".to_string());
let error_source_info = SourceInfo::new(Pos::new(1, 5), Pos::new(1, 19));
let entry_source_info = SourceInfo::new(Pos::new(1, 1), Pos::new(1, 19));
let error = RunnerError::new(error_source_info, inner, true);
let error = RunnerError::new(error_source_info, kind, true);
assert_eq!(
get_message(&error, &split_lines(content), false),
" GET http://unknown\n ^^^^^^^^^^^^^^ (6) Could not resolve host: unknown"
@ -582,12 +582,12 @@ pub mod tests {
HTTP/1.0 200
"#;
let filename = "test.hurl";
let inner = RunnerErrorKind::AssertStatus {
let kind = RunnerErrorKind::AssertStatus {
actual: "404".to_string(),
};
let error_source_info = SourceInfo::new(Pos::new(2, 10), Pos::new(2, 13));
let entry_source_info = SourceInfo::new(Pos::new(1, 1), Pos::new(1, 18));
let error = RunnerError::new(error_source_info, inner, true);
let error = RunnerError::new(error_source_info, kind, true);
assert_eq!(
get_message(&error, &split_lines(content), false),
@ -692,13 +692,13 @@ HTTP/1.0 200
```
"#;
let filename = "test.hurl";
let inner = RunnerErrorKind::AssertBodyValueError {
let kind = RunnerErrorKind::AssertBodyValueError {
actual: "<p>Hello</p>\n\n".to_string(),
expected: "<p>Hello</p>\n".to_string(),
};
let error_source_info = SourceInfo::new(Pos::new(3, 4), Pos::new(4, 1));
let entry_source_info = SourceInfo::new(Pos::new(1, 1), Pos::new(1, 20));
let error = RunnerError::new(error_source_info, inner, true);
let error = RunnerError::new(error_source_info, kind, true);
assert_eq!(
get_message(&error, &split_lines(content), false),

View File

@ -101,9 +101,7 @@ pub fn one_or_more<T>(f: ParseFunc<T>, reader: &mut Reader) -> ParseResult<Vec<T
}
}
// if zero occurrence => should fail?
Err(ParseError {
pos, kind: inner, ..
}) => Err(ParseError::new(pos, false, inner)),
Err(ParseError { pos, kind, .. }) => Err(ParseError::new(pos, false, kind)),
}
}

View File

@ -71,11 +71,11 @@ pub enum JsonErrorVariant {
impl ParseError {
/// Creates a new error for the position `pos`, of type `inner`.
pub fn new(pos: Pos, recoverable: bool, inner: ParseErrorKind) -> ParseError {
pub fn new(pos: Pos, recoverable: bool, kind: ParseErrorKind) -> ParseError {
ParseError {
pos,
recoverable,
kind: inner,
kind,
}
}

View File

@ -57,15 +57,15 @@ pub fn parse(reader: &mut Reader) -> ParseResult<Template> {
}
}
if elements.is_empty() {
let inner = ParseErrorKind::Filename;
return Err(ParseError::new(start.pos, false, inner));
let kind = ParseErrorKind::Filename;
return Err(ParseError::new(start.pos, false, kind));
}
if let Some(TemplateElement::String { encoded, .. }) = elements.first() {
if encoded.starts_with('[') {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "filename".to_string(),
};
return Err(ParseError::new(start.pos, false, inner));
return Err(ParseError::new(start.pos, false, kind));
}
}

View File

@ -58,15 +58,15 @@ pub fn parse(reader: &mut Reader) -> ParseResult<Template> {
}
}
if elements.is_empty() {
let inner = ParseErrorKind::Filename;
return Err(ParseError::new(start.pos, false, inner));
let kind = ParseErrorKind::Filename;
return Err(ParseError::new(start.pos, false, kind));
}
if let Some(TemplateElement::String { encoded, .. }) = elements.first() {
if encoded.starts_with('[') {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "filename".to_string(),
};
return Err(ParseError::new(start.pos, false, inner));
return Err(ParseError::new(start.pos, false, kind));
}
}

View File

@ -75,10 +75,10 @@ pub fn filter(reader: &mut Reader) -> ParseResult<Filter> {
)
.map_err(|e| {
if e.recoverable {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "filter".to_string(),
};
ParseError::new(e.pos, true, inner)
ParseError::new(e.pos, true, kind)
} else {
e
}

View File

@ -42,8 +42,8 @@ pub fn parse(reader: &mut Reader) -> ParseResult<JsonValue> {
fn parse_in_json(reader: &mut Reader) -> ParseResult<JsonValue> {
if let Some(c) = reader.peek() {
if c == ',' {
let inner = ParseErrorKind::Json(JsonErrorVariant::EmptyElement);
return Err(ParseError::new(reader.state.pos, false, inner));
let kind = ParseErrorKind::Json(JsonErrorVariant::EmptyElement);
return Err(ParseError::new(reader.state.pos, false, kind));
}
}
match parse(reader) {
@ -55,8 +55,8 @@ fn parse_in_json(reader: &mut Reader) -> ParseResult<JsonValue> {
ParseError {
recoverable: true, ..
} => {
let inner = ParseErrorKind::Json(JsonErrorVariant::ExpectingElement);
Err(ParseError::new(e.pos, false, inner))
let kind = ParseErrorKind::Json(JsonErrorVariant::ExpectingElement);
Err(ParseError::new(e.pos, false, kind))
}
_ => Err(ParseError::new(e.pos, false, e.kind)),
},
@ -116,17 +116,17 @@ fn any_char(reader: &mut Reader) -> ParseResult<(char, String, Pos)> {
reader.state = start;
match reader.read() {
None => {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "char".to_string(),
};
Err(ParseError::new(start.pos, true, inner))
Err(ParseError::new(start.pos, true, kind))
}
Some(c) => {
if ['\\', '\x08', '\n', '\x0c', '\r', '\t'].contains(&c) {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "char".to_string(),
};
Err(ParseError::new(start.pos, true, inner))
Err(ParseError::new(start.pos, true, kind))
} else {
Ok((c, reader.peek_back(start.cursor), start.pos))
}
@ -223,10 +223,10 @@ pub fn number_value(reader: &mut Reader) -> ParseResult<JsonValue> {
Err(_) => {
let digits = reader.read_while(|c| c.is_ascii_digit());
if digits.is_empty() {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "number".to_string(),
};
return Err(ParseError::new(start.pos, true, inner));
return Err(ParseError::new(start.pos, true, kind));
} else {
digits
}
@ -238,10 +238,10 @@ pub fn number_value(reader: &mut Reader) -> ParseResult<JsonValue> {
Ok(_) => {
let digits = reader.read_while(|c| c.is_ascii_digit());
if digits.is_empty() {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "digits".to_string(),
};
return Err(ParseError::new(reader.state.pos, false, inner));
return Err(ParseError::new(reader.state.pos, false, kind));
} else {
format!(".{digits}")
}
@ -300,8 +300,8 @@ fn list_value(reader: &mut Reader) -> ParseResult<JsonValue> {
// If there is one more comma, e.g. [1, 2,], it's better to report to the user because
// this occurrence is common.
if reader.peek_ignoring_whitespace() == Some(']') {
let inner = ParseErrorKind::Json(JsonErrorVariant::TrailingComma);
return Err(ParseError::new(save, false, inner));
let kind = ParseErrorKind::Json(JsonErrorVariant::TrailingComma);
return Err(ParseError::new(save, false, kind));
}
let element = list_element(reader)?;
elements.push(element);
@ -347,8 +347,8 @@ pub fn object_value(reader: &mut Reader) -> ParseResult<JsonValue> {
// If there is one more comma, e.g. {"a": "b",}, it's better to report to the user
// because this occurrence is common.
if reader.peek_ignoring_whitespace() == Some('}') {
let inner = ParseErrorKind::Json(JsonErrorVariant::TrailingComma);
return Err(ParseError::new(save, false, inner));
let kind = ParseErrorKind::Json(JsonErrorVariant::TrailingComma);
return Err(ParseError::new(save, false, kind));
}
let element = object_element(reader)?;
elements.push(element);
@ -366,8 +366,8 @@ fn key(reader: &mut Reader) -> ParseResult<Template> {
let save = reader.state;
let name = string_template(reader).map_err(|e| e.non_recoverable())?;
if name.elements.is_empty() {
let inner = ParseErrorKind::Json(JsonErrorVariant::EmptyElement);
Err(ParseError::new(save.pos, false, inner))
let kind = ParseErrorKind::Json(JsonErrorVariant::EmptyElement);
Err(ParseError::new(save.pos, false, kind))
} else {
Ok(name)
}
@ -387,8 +387,8 @@ fn object_element(reader: &mut Reader) -> ParseResult<JsonObjectElement> {
let next_char = reader.peek();
// Comparing to None because `next_char` can be EOF.
if next_char == Some('}') || next_char.is_none() {
let inner = ParseErrorKind::Json(JsonErrorVariant::EmptyElement);
return Err(ParseError::new(save, false, inner));
let kind = ParseErrorKind::Json(JsonErrorVariant::EmptyElement);
return Err(ParseError::new(save, false, kind));
}
let value = parse_in_json(reader)?;
let space3 = whitespace(reader);

View File

@ -50,17 +50,17 @@ pub fn parse(reader: &mut Reader) -> ParseResult<Template> {
}
}
if elements.is_empty() {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "key-string".to_string(),
};
return Err(ParseError::new(start.pos, false, inner));
return Err(ParseError::new(start.pos, false, kind));
}
if let Some(TemplateElement::String { encoded, .. }) = elements.first() {
if encoded.starts_with('[') {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "key-string".to_string(),
};
return Err(ParseError::new(start.pos, false, inner));
return Err(ParseError::new(start.pos, false, kind));
}
}

View File

@ -26,17 +26,17 @@ pub fn natural(reader: &mut Reader) -> ParseResult<u64> {
let start = reader.state;
if reader.is_eof() {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: String::from("natural"),
};
return Err(ParseError::new(start.pos, true, inner));
return Err(ParseError::new(start.pos, true, kind));
}
let first_digit = reader.read().unwrap();
if !first_digit.is_ascii_digit() {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: String::from("natural"),
};
return Err(ParseError::new(start.pos, true, inner));
return Err(ParseError::new(start.pos, true, kind));
}
let save = reader.state;
@ -44,18 +44,18 @@ pub fn natural(reader: &mut Reader) -> ParseResult<u64> {
// if the first digit is zero, you should not have any more digits
if first_digit == '0' && !s.is_empty() {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: String::from("natural"),
};
return Err(ParseError::new(save.pos, false, inner));
return Err(ParseError::new(save.pos, false, kind));
}
match format!("{first_digit}{s}").parse() {
Ok(value) => Ok(value),
Err(_) => {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: String::from("natural"),
};
Err(ParseError::new(save.pos, false, inner))
Err(ParseError::new(save.pos, false, kind))
}
}
}
@ -77,18 +77,18 @@ pub fn number(reader: &mut Reader) -> ParseResult<Number> {
};
let integer_digits = reader.read_while(|c| c.is_ascii_digit());
if integer_digits.is_empty() {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "number".to_string(),
};
return Err(ParseError::new(reader.state.pos, true, inner));
return Err(ParseError::new(reader.state.pos, true, kind));
// if the first digit is zero, you should not have any more digits
} else if integer_digits.len() > 1 && integer_digits.starts_with('0') {
let save = reader.state;
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: String::from("natural"),
};
return Err(ParseError::new(save.pos, false, inner));
return Err(ParseError::new(save.pos, false, kind));
}
// Float
@ -96,10 +96,10 @@ pub fn number(reader: &mut Reader) -> ParseResult<Number> {
let save = reader.state;
let decimal_digits = reader.read_while(|c| c.is_ascii_digit());
if decimal_digits.is_empty() {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: String::from("decimal digits"),
};
return Err(ParseError::new(save.pos, false, inner));
return Err(ParseError::new(save.pos, false, kind));
}
match format!("{sign}{integer_digits}.{decimal_digits}").parse() {
Ok(value) => {
@ -107,10 +107,10 @@ pub fn number(reader: &mut Reader) -> ParseResult<Number> {
Ok(Number::Float(Float { value, encoded }))
}
Err(_) => {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: String::from("float"),
};
Err(ParseError::new(start.pos, false, inner))
Err(ParseError::new(start.pos, false, kind))
}
}

View File

@ -260,10 +260,10 @@ fn retry(reader: &mut Reader) -> ParseResult<Retry> {
} else if value > 0 {
Ok(Retry::Finite(value as usize))
} else {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "Expecting a retry value".to_string(),
};
Err(ParseError::new(pos, false, inner))
Err(ParseError::new(pos, false, kind))
}
}
@ -274,10 +274,10 @@ fn boolean_option(reader: &mut Reader) -> ParseResult<BooleanOption> {
Err(_) => {
reader.state = start;
let exp = expr::parse(reader).map_err(|e| {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "true|false".to_string(),
};
ParseError::new(e.pos, false, inner)
ParseError::new(e.pos, false, kind)
})?;
Ok(BooleanOption::Expression(exp))
}
@ -291,10 +291,10 @@ fn natural_option(reader: &mut Reader) -> ParseResult<NaturalOption> {
Err(_) => {
reader.state = start;
let exp = expr::parse(reader).map_err(|e| {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "integer".to_string(),
};
ParseError::new(e.pos, false, inner)
ParseError::new(e.pos, false, kind)
})?;
Ok(NaturalOption::Expression(exp))
}
@ -308,10 +308,10 @@ fn retry_option(reader: &mut Reader) -> ParseResult<RetryOption> {
Err(_) => {
reader.state = start;
let exp = expr::parse(reader).map_err(|e| {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "integer".to_string(),
};
ParseError::new(e.pos, false, inner)
ParseError::new(e.pos, false, kind)
})?;
Ok(RetryOption::Expression(exp))
}
@ -336,10 +336,10 @@ fn variable_name(reader: &mut Reader) -> ParseResult<String> {
let start = reader.state;
let name = reader.read_while(|c| c.is_alphanumeric() || *c == '_' || *c == '-');
if name.is_empty() {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "variable name".to_string(),
};
return Err(ParseError::new(start.pos, false, inner));
return Err(ParseError::new(start.pos, false, kind));
}
Ok(name)
}
@ -371,10 +371,10 @@ fn variable_value(reader: &mut Reader) -> ParseResult<VariableValue> {
reader,
)
.map_err(|e| {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "variable value".to_string(),
};
ParseError::new(e.pos, false, inner)
ParseError::new(e.pos, false, kind)
})
}

View File

@ -115,16 +115,16 @@ fn response(reader: &mut Reader) -> ParseResult<Response> {
fn method(reader: &mut Reader) -> ParseResult<Method> {
if reader.is_eof() {
let inner = ParseErrorKind::Method {
let kind = ParseErrorKind::Method {
name: "<EOF>".to_string(),
};
return Err(ParseError::new(reader.state.pos, true, inner));
return Err(ParseError::new(reader.state.pos, true, kind));
}
let start = reader.state;
let name = reader.read_while(|c| c.is_ascii_alphabetic());
if name.is_empty() || name.to_uppercase() != name {
let inner = ParseErrorKind::Method { name };
Err(ParseError::new(start.pos, false, inner))
let kind = ParseErrorKind::Method { name };
Err(ParseError::new(start.pos, false, kind))
} else {
Ok(Method(name))
}

View File

@ -71,12 +71,12 @@ pub fn predicate_value(reader: &mut Reader) -> ParseResult<PredicateValue> {
reader,
)
.map_err(|e| {
let inner = if e.recoverable {
let kind = if e.recoverable {
ParseErrorKind::PredicateValue
} else {
e.kind
};
ParseError::new(e.pos, false, inner)
ParseError::new(e.pos, false, kind)
})
}

View File

@ -81,10 +81,10 @@ pub fn line_terminator(reader: &mut Reader) -> ParseResult<LineTerminator> {
match newline(reader) {
Ok(r) => r,
Err(e) => {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: String::from("line_terminator"),
};
return Err(ParseError::new(e.pos, false, inner));
return Err(ParseError::new(e.pos, false, kind));
}
}
};
@ -138,17 +138,17 @@ pub fn literal(s: &str, reader: &mut Reader) -> ParseResult<()> {
let _state = reader.state;
match reader.read() {
None => {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: s.to_string(),
};
return Err(ParseError::new(start.pos, false, inner));
return Err(ParseError::new(start.pos, false, kind));
}
Some(x) => {
if x != c {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: s.to_string(),
};
return Err(ParseError::new(start.pos, false, inner));
return Err(ParseError::new(start.pos, false, kind));
} else {
continue;
}
@ -181,10 +181,10 @@ pub fn try_literals(s1: &str, s2: &str, reader: &mut Reader) -> ParseResult<Stri
Ok(_) => Ok(s2.to_string()),
Err(_) => {
reader.state = start;
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: format!("<{s1}> or <{s2}>"),
};
Err(ParseError::new(start.pos, true, inner))
Err(ParseError::new(start.pos, true, kind))
}
}
}
@ -204,10 +204,10 @@ pub fn newline(reader: &mut Reader) -> ParseResult<Whitespace> {
source_info: SourceInfo::new(start.pos, reader.state.pos),
}),
Err(_) => {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: String::from("newline"),
};
Err(ParseError::new(start.pos, false, inner))
Err(ParseError::new(start.pos, false, kind))
}
},
}
@ -290,10 +290,10 @@ pub fn regex(reader: &mut Reader) -> ParseResult<Regex> {
loop {
match reader.read() {
None => {
let inner = ParseErrorKind::RegexExpr {
let kind = ParseErrorKind::RegexExpr {
message: "unexpected end of file".to_string(),
};
return Err(ParseError::new(reader.state.pos, false, inner));
return Err(ParseError::new(reader.state.pos, false, kind));
}
Some('/') => break,
Some('\\') => {
@ -351,10 +351,10 @@ pub fn boolean(reader: &mut Reader) -> ParseResult<bool> {
Err(_) => match literal("false", reader) {
Ok(_) => Ok(false),
Err(_) => {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: String::from("true|false"),
};
Err(ParseError::new(start.pos, true, inner))
Err(ParseError::new(start.pos, true, kind))
}
},
}
@ -401,10 +401,10 @@ pub fn eof(reader: &mut Reader) -> ParseResult<()> {
if reader.is_eof() {
Ok(())
} else {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: String::from("eof"),
};
Err(ParseError::new(reader.state.pos, false, inner))
Err(ParseError::new(reader.state.pos, false, kind))
}
}

View File

@ -145,10 +145,10 @@ pub fn regex_value(reader: &mut Reader) -> ParseResult<RegexValue> {
reader,
)
.map_err(|e| {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "\" or /".to_string(),
};
ParseError::new(e.pos, false, inner)
ParseError::new(e.pos, false, kind)
})
}
@ -204,9 +204,9 @@ fn certificate_field(reader: &mut Reader) -> ParseResult<CertificateAttributeNam
} else {
let value =
"Field <Subject>, <Issuer>, <Start-Date>, <Expire-Date> or <Serial-Number>".to_string();
let inner = ParseErrorKind::Expecting { value };
let kind = ParseErrorKind::Expecting { value };
let pos = reader.state.pos;
Err(ParseError::new(pos, false, inner))
Err(ParseError::new(pos, false, kind))
}
}

View File

@ -54,9 +54,9 @@ fn request_section(reader: &mut Reader) -> ParseResult<Section> {
"Cookies" => section_value_cookies(reader)?,
"Options" => section_value_options(reader)?,
_ => {
let inner = ParseErrorKind::RequestSectionName { name: name.clone() };
let kind = ParseErrorKind::RequestSectionName { name: name.clone() };
let pos = Pos::new(start.line, start.column + 1);
return Err(ParseError::new(pos, false, inner));
return Err(ParseError::new(pos, false, kind));
}
};
@ -83,9 +83,9 @@ fn response_section(reader: &mut Reader) -> ParseResult<Section> {
"Captures" => section_value_captures(reader)?,
"Asserts" => section_value_asserts(reader)?,
_ => {
let inner = ParseErrorKind::ResponseSectionName { name: name.clone() };
let kind = ParseErrorKind::ResponseSectionName { name: name.clone() };
let pos = Pos::new(start.line, start.column + 1);
return Err(ParseError::new(pos, false, inner));
return Err(ParseError::new(pos, false, kind));
}
};
@ -104,10 +104,10 @@ fn section_name(reader: &mut Reader) -> ParseResult<String> {
let name = reader.read_while(|c| c.is_alphanumeric());
if name.is_empty() {
// Could be the empty json array for the body
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "a valid section name".to_string(),
};
return Err(ParseError::new(pos, true, inner));
return Err(ParseError::new(pos, true, kind));
}
try_literal("]", reader)?;
Ok(name)

View File

@ -174,19 +174,19 @@ fn any_char(except: Vec<char>, reader: &mut Reader) -> ParseResult<(char, String
reader.state = start;
match reader.read() {
None => {
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "char".to_string(),
};
Err(ParseError::new(start.pos, true, inner))
Err(ParseError::new(start.pos, true, kind))
}
Some(c) => {
if except.contains(&c)
|| ['\\', '\x08', '\n', '\x0c', '\r', '\t'].contains(&c)
{
let inner = ParseErrorKind::Expecting {
let kind = ParseErrorKind::Expecting {
value: "char".to_string(),
};
Err(ParseError::new(start.pos, true, inner))
Err(ParseError::new(start.pos, true, kind))
} else {
Ok((c, reader.peek_back(start.cursor)))
}

View File

@ -118,13 +118,13 @@ pub fn templatize(encoded_string: EncodedString) -> ParseResult<Vec<TemplateElem
encoded.push('{');
}
State::Template | State::FirstCloseBracket => {
let inner = error::ParseErrorKind::Expecting {
let kind = error::ParseErrorKind::Expecting {
value: "}}".to_string(),
};
return Err(error::ParseError::new(
encoded_string.source_info.end,
false,
inner,
kind,
));
}
}