diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a354eb72..a04c965e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -93,11 +93,7 @@ jobs: strategy: matrix: target: ["x86_64-unknown-linux-gnu", "thumbv6m-none-eabi"] - features: - [ - "", - "derive", - ] + features: ["", "derive"] include: - target: "x86_64-unknown-linux-gnu" extra_features: "std,log" @@ -138,4 +134,4 @@ jobs: uses: actions-rs/cargo@v1 with: command: test - args: --workspace --features std,heapless \ No newline at end of file + args: --workspace --features std,heapless,string_errors diff --git a/atat/Cargo.toml b/atat/Cargo.toml index 02a9ac81..99468ce1 100644 --- a/atat/Cargo.toml +++ b/atat/Cargo.toml @@ -53,3 +53,4 @@ custom-error-messages = [] std = ["serde_at/std", "nom/std", "embassy-time/std", "embedded-io/std"] hex_str_arrays = [] heapless = ["serde_at/heapless"] +string_errors = [] diff --git a/atat/src/digest.rs b/atat/src/digest.rs index 4edbbfbc..c1257faf 100644 --- a/atat/src/digest.rs +++ b/atat/src/digest.rs @@ -201,7 +201,7 @@ pub mod parser { branch::alt, bytes::streaming::tag, character::complete, - combinator::{eof, map, map_res, not, recognize}, + combinator::{eof, map, map_res, recognize}, error::ParseError, sequence::tuple, IResult, @@ -256,6 +256,7 @@ pub mod parser { ) }), // Matches the equivalent of regex: "\r\n\+CME ERROR:\s*([^\n\r]+)\r\n" + #[cfg(feature = "string_errors")] map(string_error("\r\n+CME ERROR:"), |(error_msg, len)| { ( DigestResult::Response(Err(InternalError::CmeError(CmeError::from_msg( @@ -265,6 +266,7 @@ pub mod parser { ) }), // Matches the equivalent of regex: "\r\n\+CMS ERROR:\s*([^\n\r]+)\r\n" + #[cfg(feature = "string_errors")] map(string_error("\r\n+CMS ERROR:"), |(error_msg, len)| { ( DigestResult::Response(Err(InternalError::CmsError(CmsError::from_msg( @@ -397,6 +399,7 @@ pub mod parser { } /// Matches the equivalent of regex: "{token}\s*([^\n\r]+)\r\n" + #[cfg(feature = "string_errors")] fn string_error<'a, T, Error: ParseError<&'a [u8]>>( token: T, ) -> impl Fn(&'a [u8]) -> IResult<&'a [u8], (&'a [u8], usize), Error> @@ -407,7 +410,7 @@ pub mod parser { move |i| { let (i, (prefix_data, _, error_msg)) = tuple(( recognize(take_until_including(token.clone())), - not(tag("\r")), + nom::combinator::not(tag("\r")), recognize(take_until_including("\r\n")), ))(i)?; @@ -554,6 +557,7 @@ mod test { } #[test] + #[cfg(feature = "string_errors")] fn mm_error() { let tests: Vec<(&[u8], DigestResult, usize)> = vec![ (b"\r\nUNKNOWN COMMAND\r\n", DigestResult::None, 0), @@ -1044,6 +1048,7 @@ mod test { } #[test] + #[cfg(feature = "string_errors")] fn verbose_error_response() { let mut digester = AtDigester::::new(); let mut buf = heapless::Vec::::new(); diff --git a/atat/src/error/cme_error.rs b/atat/src/error/cme_error.rs index 6d41f77d..6ff74066 100644 --- a/atat/src/error/cme_error.rs +++ b/atat/src/error/cme_error.rs @@ -502,6 +502,7 @@ impl From for CmeError { } } +#[cfg(feature = "string_errors")] impl CmeError { pub const fn from_msg(s: &[u8]) -> Self { // FIXME: diff --git a/atat/src/error/cms_error.rs b/atat/src/error/cms_error.rs index 2231da88..e8838927 100644 --- a/atat/src/error/cms_error.rs +++ b/atat/src/error/cms_error.rs @@ -84,6 +84,7 @@ impl From for CmsError { } } +#[cfg(feature = "string_errors")] impl CmsError { pub const fn from_msg(s: &[u8]) -> Self { // FIXME: