Skip to content

Commit

Permalink
Normalize guid errors to allow easier anonymizing/aggregation of data (
Browse files Browse the repository at this point in the history
…#71)

* Normalize guid-related errors to allow easier anonymizing/aggregation of data
  • Loading branch information
skhamis authored Jun 22, 2022
1 parent f2810fd commit 1d290d7
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,42 @@ impl From<Utf8Error> for Error {

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// We format the guid-specific params with <guid: {}> to make it easier on the
// telemetry side to parse out the user-specific guid and normalize the errors
// to better aggregate the data
match self.kind() {
ErrorKind::MismatchedItemKind(local_item, remote_item) => write!(
f,
"Can't merge local {} {} and remote {} {}",
"Can't merge local {} <guid: {}> and remote {} <guid: {}>",
local_item.kind, local_item.guid, remote_item.kind, remote_item.guid,
),
ErrorKind::DuplicateItem(guid) => write!(f, "Item {} already exists in tree", guid),
ErrorKind::MissingItem(guid) => write!(f, "Item {} doesn't exist in tree", guid),
ErrorKind::DuplicateItem(guid) => {
write!(f, "Item <guid: {}> already exists in tree", guid)
}
ErrorKind::MissingItem(guid) => {
write!(f, "Item <guid: {}> doesn't exist in tree", guid)
}
ErrorKind::InvalidParent(child, parent) => write!(
f,
"Can't insert {} {} into {} {}",
"Can't insert {} <guid: {}> into {} <guid: {}>",
child.kind, child.guid, parent.kind, parent.guid,
),
ErrorKind::InvalidParentForUnknownChild(child_guid, parent) => write!(
f,
"Can't insert unknown child {} into {} {}",
"Can't insert unknown child <guid: {}> into {} <guid: {}>",
child_guid, parent.kind, parent.guid,
),
ErrorKind::MissingParent(child, parent_guid) => write!(
f,
"Can't insert {} {} into nonexistent parent {}",
"Can't insert {} <guid: {}> into nonexistent parent <guid: {}>",
child.kind, child.guid, parent_guid,
),
ErrorKind::MissingParentForUnknownChild(child_guid, parent_guid) => write!(
f,
"Can't insert unknown child {} into nonexistent parent {}",
"Can't insert unknown child <guid: {}> into nonexistent parent <guid: {}>",
child_guid, parent_guid,
),
ErrorKind::Cycle(guid) => write!(f, "Item {} can't contain itself", guid),
ErrorKind::Cycle(guid) => write!(f, "Item <guid: {}> can't contain itself", guid),
ErrorKind::MergeConflict => write!(f, "Local tree changed during merge"),
ErrorKind::UnmergedLocalItems => {
write!(f, "Merged tree doesn't mention all items from local tree")
Expand All @@ -94,9 +101,13 @@ impl fmt::Display for Error {
write!(f, "Merged tree doesn't mention all items from remote tree")
}
ErrorKind::InvalidGuid(invalid_guid) => {
write!(f, "Merged tree contains invalid GUID {}", invalid_guid)
write!(
f,
"Merged tree contains invalid GUID <guid: {}>",
invalid_guid
)
}
ErrorKind::InvalidByte(b) => write!(f, "Invalid byte {} in UTF-16 encoding", b),
ErrorKind::InvalidByte(b) => write!(f, "Invalid byte <byte: {}> in UTF-16 encoding", b),
ErrorKind::MalformedString(err) => err.fmt(f),
ErrorKind::Abort => write!(f, "Operation aborted"),
}
Expand Down

0 comments on commit 1d290d7

Please sign in to comment.