Skip to content

Commit

Permalink
Feature gate string to error conversions behind feature gate, for cme…
Browse files Browse the repository at this point in the history
…/cms errors
  • Loading branch information
MathiasKoch committed Aug 9, 2024
1 parent a466836 commit 48796f3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions atat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
9 changes: 7 additions & 2 deletions atat/src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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>
Expand All @@ -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)?;

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -1044,6 +1048,7 @@ mod test {
}

#[test]
#[cfg(feature = "string_errors")]
fn verbose_error_response() {
let mut digester = AtDigester::<UrcTestParser>::new();
let mut buf = heapless::Vec::<u8, TEST_RX_BUF_LEN>::new();
Expand Down
1 change: 1 addition & 0 deletions atat/src/error/cme_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ impl From<u16> for CmeError {
}
}

#[cfg(feature = "string_errors")]
impl CmeError {
pub const fn from_msg(s: &[u8]) -> Self {
// FIXME:
Expand Down
1 change: 1 addition & 0 deletions atat/src/error/cms_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl From<u16> for CmsError {
}
}

#[cfg(feature = "string_errors")]
impl CmsError {
pub const fn from_msg(s: &[u8]) -> Self {
// FIXME:
Expand Down

0 comments on commit 48796f3

Please sign in to comment.