From 54a8c976269d07a38a8ac053ae263f8d00603acf Mon Sep 17 00:00:00 2001 From: brizental Date: Thu, 16 Jul 2020 17:53:36 +0200 Subject: [PATCH 1/2] Fix int32 to ErrorType mapping --- CHANGELOG.md | 3 +++ glean-core/src/error_recording.rs | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) 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); From 8166ad4e0c684e52f0b0639287c14b2b00069ba7 Mon Sep 17 00:00:00 2001 From: brizental Date: Fri, 17 Jul 2020 14:11:35 +0200 Subject: [PATCH 2/2] Attend to review comments --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f39d04d84..491b1f069e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Unreleased changes * General - * BUGFIX: fix `int32` to `ErrorType` mapping. ([#1063](https://github.com/mozilla/glean/pull/1063)) + * BUGFIX: fix `int32` to `ErrorType` mapping. The `InvalidOverflow` had a value mismatch between glean-core and the bindings. This would only be a problem in unit tests. ([#1063](https://github.com/mozilla/glean/pull/1063)) [Full changelog](https://github.com/mozilla/glean/compare/v31.4.0...main)