diff --git a/CHANGELOG.md b/CHANGELOG.md index ab8e4c514e..6f39d04d84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Unreleased changes +* General + * BUGFIX: fix `int32` to `ErrorType` mapping. ([#1063](https://github.com/mozilla/glean/pull/1063)) + [Full changelog](https://github.com/mozilla/glean/compare/v31.4.0...main) # v31.4.0 (2020-07-16) diff --git a/glean-core/src/error_recording.rs b/glean-core/src/error_recording.rs index e5fd6fdb8c..73f3eb8239 100644 --- a/glean-core/src/error_recording.rs +++ b/glean-core/src/error_recording.rs @@ -26,7 +26,7 @@ use crate::Lifetime; /// Note: the cases in this enum must be kept in sync with the ones /// in the platform-specific code (e.g. ErrorType.kt) and with the /// metrics in the registry files. -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum ErrorType { /// For when the value to be recorded does not match the metric-specific restrictions InvalidValue, @@ -58,7 +58,7 @@ impl TryFrom for ErrorType { 0 => Ok(ErrorType::InvalidValue), 1 => Ok(ErrorType::InvalidLabel), 2 => Ok(ErrorType::InvalidState), - 4 => Ok(ErrorType::InvalidOverflow), + 3 => Ok(ErrorType::InvalidOverflow), e => Err(ErrorKind::Lifetime(e).into()), } } @@ -155,6 +155,18 @@ mod test { use crate::metrics::*; use crate::tests::new_glean; + #[test] + fn error_type_i32_mapping() { + let error: ErrorType = std::convert::TryFrom::try_from(0).unwrap(); + assert_eq!(error, ErrorType::InvalidValue); + let error: ErrorType = std::convert::TryFrom::try_from(1).unwrap(); + assert_eq!(error, ErrorType::InvalidLabel); + let error: ErrorType = std::convert::TryFrom::try_from(2).unwrap(); + assert_eq!(error, ErrorType::InvalidState); + let error: ErrorType = std::convert::TryFrom::try_from(3).unwrap(); + assert_eq!(error, ErrorType::InvalidOverflow); + } + #[test] fn recording_of_all_error_types() { let (glean, _t) = new_glean(None);