From 0c92430520046e9706ca14ecc9b9216599babb61 Mon Sep 17 00:00:00 2001 From: jcamiel Date: Mon, 4 Dec 2023 17:56:52 +0100 Subject: [PATCH] Better hexadecimal digit parsing error description. --- integration/hurl/tests_error_parser/hexdigit.err | 7 +++++++ integration/hurl/tests_error_parser/hexdigit.exit | 1 + integration/hurl/tests_error_parser/hexdigit.hurl | 3 +++ integration/hurl/tests_error_parser/hexdigit.ps1 | 3 +++ integration/hurl/tests_error_parser/hexdigit.sh | 3 +++ packages/hurl_core/src/error/mod.rs | 6 +++--- 6 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 integration/hurl/tests_error_parser/hexdigit.err create mode 100644 integration/hurl/tests_error_parser/hexdigit.exit create mode 100644 integration/hurl/tests_error_parser/hexdigit.hurl create mode 100644 integration/hurl/tests_error_parser/hexdigit.ps1 create mode 100755 integration/hurl/tests_error_parser/hexdigit.sh diff --git a/integration/hurl/tests_error_parser/hexdigit.err b/integration/hurl/tests_error_parser/hexdigit.err new file mode 100644 index 000000000..b4d9ef66f --- /dev/null +++ b/integration/hurl/tests_error_parser/hexdigit.err @@ -0,0 +1,7 @@ +error: Parsing hexadecimal number + --> tests_error_parser/hexdigit.hurl:2:17 + | + 2 | {"smiley":"\uf64"} + | ^ expecting a valid hexadecimal number + | + diff --git a/integration/hurl/tests_error_parser/hexdigit.exit b/integration/hurl/tests_error_parser/hexdigit.exit new file mode 100644 index 000000000..d8263ee98 --- /dev/null +++ b/integration/hurl/tests_error_parser/hexdigit.exit @@ -0,0 +1 @@ +2 \ No newline at end of file diff --git a/integration/hurl/tests_error_parser/hexdigit.hurl b/integration/hurl/tests_error_parser/hexdigit.hurl new file mode 100644 index 000000000..8dcd53407 --- /dev/null +++ b/integration/hurl/tests_error_parser/hexdigit.hurl @@ -0,0 +1,3 @@ +POST http://localhost:8000/data +{"smiley":"\uf64"} +HTTP 200 diff --git a/integration/hurl/tests_error_parser/hexdigit.ps1 b/integration/hurl/tests_error_parser/hexdigit.ps1 new file mode 100644 index 000000000..b7f59a491 --- /dev/null +++ b/integration/hurl/tests_error_parser/hexdigit.ps1 @@ -0,0 +1,3 @@ +Set-StrictMode -Version latest +$ErrorActionPreference = 'Stop' +hurl tests_error_parser/hexdigit.hurl diff --git a/integration/hurl/tests_error_parser/hexdigit.sh b/integration/hurl/tests_error_parser/hexdigit.sh new file mode 100755 index 000000000..e539967d0 --- /dev/null +++ b/integration/hurl/tests_error_parser/hexdigit.sh @@ -0,0 +1,3 @@ +#!/bin/bash +set -Eeuo pipefail +hurl tests_error_parser/hexdigit.hurl diff --git a/packages/hurl_core/src/error/mod.rs b/packages/hurl_core/src/error/mod.rs index 4af2ef999..5ae981e78 100644 --- a/packages/hurl_core/src/error/mod.rs +++ b/packages/hurl_core/src/error/mod.rs @@ -42,6 +42,7 @@ impl Error for parser::Error { ParseError::FileContentType => "Parsing file content type".to_string(), ParseError::Filename => "Parsing filename".to_string(), ParseError::GraphQlVariables => "Parsing GraphQL variables".to_string(), + ParseError::HexDigit => "Parsing hexadecimal number".to_string(), ParseError::InvalidCookieAttribute => "Parsing cookie attribute".to_string(), ParseError::Json(_) => "Parsing JSON".to_string(), ParseError::JsonPathExpr => "Parsing JSONPath expression".to_string(), @@ -65,7 +66,6 @@ impl Error for parser::Error { ParseError::Xml => "Parsing XML".to_string(), // TODO: implement all variants // _ => , - ParseError::HexDigit => format!("{self:?}"), ParseError::InvalidOption => format!("{self:?}"), ParseError::Unicode => format!("{self:?}"), ParseError::Url => format!("{self:?}"), @@ -73,7 +73,7 @@ impl Error for parser::Error { } fn fixme(&self) -> String { - match self.inner.clone() { + match &self.inner { ParseError::DuplicateSection => "the section is already defined".to_string(), ParseError::EscapeChar => "the escaping sequence is not valid".to_string(), ParseError::Expecting { value } => format!("expecting '{value}'"), @@ -82,6 +82,7 @@ impl Error for parser::Error { ParseError::GraphQlVariables => { "GraphQL variables is not a valid JSON object".to_string() } + ParseError::HexDigit => "expecting a valid hexadecimal number".to_string(), ParseError::InvalidCookieAttribute => "the cookie attribute is not valid".to_string(), ParseError::Json(variant) => match variant { JsonErrorVariant::TrailingComma => "trailing comma is not allowed".to_string(), @@ -141,7 +142,6 @@ impl Error for parser::Error { ParseError::Xml => "invalid XML".to_string(), // TODO: implement all variants // _ => format!("{self:?}"), - ParseError::HexDigit => format!("{self:?}"), ParseError::InvalidOption => format!("{self:?}"), ParseError::Unicode => format!("{self:?}"), ParseError::Url => format!("{self:?}"),