-
-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
options.ignoredErrors
accepting String and Regex (#4083)
* Add `options.ignoreExceptions` accepting String and Regex * address comments, add tests, add entry to CHANGELOG.md * Update CHANGELOG.md * implement ignoredErrors instead of ignoredExceptions, matching on several possible messages as in the JS SDK and not on only on the Exception class * add JavaDoc, update CHANGELOG.md, don't consider `event.exceptions`
- Loading branch information
Showing
12 changed files
with
247 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.sentry.util; | ||
|
||
import io.sentry.FilterString; | ||
import io.sentry.SentryEvent; | ||
import io.sentry.protocol.Message; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public final class ErrorUtils { | ||
|
||
/** Checks if an error has been ignored. */ | ||
@ApiStatus.Internal | ||
public static boolean isIgnored( | ||
final @Nullable List<FilterString> ignoredErrors, final @NotNull SentryEvent event) { | ||
if (event == null || ignoredErrors == null || ignoredErrors.isEmpty()) { | ||
return false; | ||
} | ||
|
||
final @NotNull Set<String> possibleMessages = new HashSet<>(); | ||
|
||
final @Nullable Message eventMessage = event.getMessage(); | ||
if (eventMessage != null) { | ||
final @Nullable String stringMessage = eventMessage.getMessage(); | ||
if (stringMessage != null) { | ||
possibleMessages.add(stringMessage); | ||
} | ||
final @Nullable String formattedMessage = eventMessage.getFormatted(); | ||
if (formattedMessage != null) { | ||
possibleMessages.add(formattedMessage); | ||
} | ||
} | ||
final @Nullable Throwable throwable = event.getThrowable(); | ||
if (throwable != null) { | ||
possibleMessages.add(throwable.toString()); | ||
} | ||
|
||
for (final @NotNull FilterString filter : ignoredErrors) { | ||
if (possibleMessages.contains(filter.getFilterString())) { | ||
return true; | ||
} | ||
} | ||
|
||
for (final @NotNull FilterString filter : ignoredErrors) { | ||
for (final @NotNull String message : possibleMessages) { | ||
if (filter.matches(message)) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.