Skip to content

Commit

Permalink
Fix int32 to ErrorType mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
brizental committed Jul 16, 2020
1 parent 2ca23ee commit b1a7abe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
16 changes: 14 additions & 2 deletions glean-core/src/error_recording.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -58,7 +58,7 @@ impl TryFrom<i32> 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()),
}
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b1a7abe

Please sign in to comment.