Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log unhandled FiatProviderError errors #5326

Merged
merged 6 commits into from
Oct 25, 2024
Merged

Conversation

samholmes
Copy link
Contributor

@samholmes samholmes commented Oct 25, 2024

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes
  • No

Dependencies

#5322 (review)

Requirements

If you have made any visual changes to the GUI. Make sure you have:

  • Tested on iOS device
  • Tested on Android device
  • Tested on small-screen device (iPod Touch)
  • Tested on large-screen device (tablet)

Copy link
Contributor

@swansontec swansontec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, but I don't know if the recursion is a good idea.

Comment on lines 163 to 168
let hint: { event_id?: string; data?: { [key: string]: any } } | undefined
if (tag != null) {
hint = { event_id: tag }
}
if (metadata != null) {
hint = { data: metadata }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't let us have both a tag and a metadata at the same time. Maybe do something like this:

let hint: { event_id?: string; data?: { [key: string]: any } } = {}
if (tag != null) hint.event_id = tag
if (metadata != null) hint.data = metadata
captureException(err, tag != null || metadata != null ? hint : undefined)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is replaced because it turns out it didn't do what we expected it to do for the events we send to Sentry. In some cases, it harmed us.

Comment on lines 111 to 115
// Recurse over objects with added prefix keys:
if (typeof value === 'object' && value !== null) {
addMetadataToContext(context, value, allKeys)
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just JSON.stringify instead of recursing? Imagine you have something like this:

{
  fromCoin: { tokenId: 'asf', pluginId: 'asdf' },
  toCoin: { tokenId: 'dda', pluginId: 'asafadf' }
}

The fields in toCoin would stomp over the fields in fromCoin, and you would lose information. If we use JSON.stringify on the values, then you would get:

{
  fromCoin: '{"tokenId":"asf","pluginId":"asdf"}',
  toCoin: '{"tokenId":"dda","pluginId":"asafadf"}'
}

This would be more usable, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why: JSON strings are big and when metadata fields are too big, they're filtered out by Sentry. So, I flattened the JSON objects into separate fields. Each field contains the parent key in it's name so there shoulnd't be possibility of key stomping

1. Isolation normalization into new utility to de-dup error handling
2. Use `normalizeError` util at the end (trackError)
3. Fully remove i18n from error objects; only present localized strings
   in the UI.

Translating error messages is be a locale issue. Maintaining our errors
in the default language is more consistent and consistency is better
when it comes to error tracking.

If "to translate" an error means something other than i18n, such as to
translate the error object and any special properties into a useful
message for reporting, then a new function should be introduced for
that purpose (call it `encodeError` or something of that nature).
Should an array be thrown, we'll normalize into an AggregateError type
of object, and we'll concatenate localized error messages for i18n.
The hint data is incorrectly implemented and causing major issues:

1. `event_id` is a hex value and any other value cause the error to not
   be reported.
2. `data` in the hint is only used locally before sending the event to
   Sentry.

Instead we will use the `scope` API to add the proper event tagging and
metadata. We can leverage the `addMetadataToContext` function to
consistently process metadata for a Sentry event.
The name was the message, and the message didn't exist. Now we'll create
a useful message from the info parameter.
@samholmes samholmes merged commit 8d48af9 into develop Oct 25, 2024
2 checks passed
@samholmes samholmes deleted the sam/fiat-error-tracking branch October 25, 2024 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants