Skip to content

Commit 4f7e775

Browse files
committed
feat(Client): Added notify(Throwable, ErrorOptions) to Client & Bugsnag
1 parent 697444e commit 4f7e775

File tree

3 files changed

+76
-67
lines changed

3 files changed

+76
-67
lines changed

bugsnag-android-core/api/bugsnag-android-core.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public final class com/bugsnag/android/Bugsnag {
8282
public static fun leaveBreadcrumb (Ljava/lang/String;Ljava/util/Map;Lcom/bugsnag/android/BreadcrumbType;)V
8383
public static fun markLaunchCompleted ()V
8484
public static fun notify (Ljava/lang/Throwable;)V
85+
public static fun notify (Ljava/lang/Throwable;Lcom/bugsnag/android/ErrorOptions;)V
8586
public static fun notify (Ljava/lang/Throwable;Lcom/bugsnag/android/ErrorOptions;Lcom/bugsnag/android/OnErrorCallback;)V
8687
public static fun notify (Ljava/lang/Throwable;Lcom/bugsnag/android/OnErrorCallback;)V
8788
public static fun pauseSession ()V
@@ -140,6 +141,7 @@ public class com/bugsnag/android/Client : com/bugsnag/android/CallbackAware, com
140141
public fun leaveBreadcrumb (Ljava/lang/String;Ljava/util/Map;Lcom/bugsnag/android/BreadcrumbType;)V
141142
public fun markLaunchCompleted ()V
142143
public fun notify (Ljava/lang/Throwable;)V
144+
public fun notify (Ljava/lang/Throwable;Lcom/bugsnag/android/ErrorOptions;)V
143145
public fun notify (Ljava/lang/Throwable;Lcom/bugsnag/android/ErrorOptions;Lcom/bugsnag/android/OnErrorCallback;)V
144146
public fun notify (Ljava/lang/Throwable;Lcom/bugsnag/android/OnErrorCallback;)V
145147
public fun pauseSession ()V

bugsnag-android-core/src/main/java/com/bugsnag/android/Bugsnag.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ public static void notify(@NonNull final Throwable exception,
255255
getClient().notify(exception, onError);
256256
}
257257

258+
/**
259+
* Notify Bugsnag of a handled exception
260+
*
261+
* @param exception the exception to send to Bugsnag
262+
* @param options additional options to adjust the reporting of the exception
263+
*/
264+
public static void notify(@NonNull final Throwable exception,
265+
@Nullable final ErrorOptions options) {
266+
getClient().notify(exception, options);
267+
}
268+
258269
/**
259270
* Notify Bugsnag of a handled exception
260271
*

bugsnag-android-core/src/main/java/com/bugsnag/android/Client.java

Lines changed: 63 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
import static com.bugsnag.android.SeverityReason.REASON_HANDLED_EXCEPTION;
44

5+
import android.app.Application;
6+
import android.content.Context;
7+
8+
import androidx.annotation.NonNull;
9+
import androidx.annotation.Nullable;
10+
import androidx.annotation.VisibleForTesting;
11+
512
import com.bugsnag.android.internal.BackgroundTaskService;
613
import com.bugsnag.android.internal.ForegroundDetector;
714
import com.bugsnag.android.internal.ImmutableConfig;
@@ -15,16 +22,6 @@
1522
import com.bugsnag.android.internal.dag.Provider;
1623
import com.bugsnag.android.internal.dag.SystemServiceModule;
1724

18-
import android.app.Application;
19-
import android.content.Context;
20-
21-
import androidx.annotation.NonNull;
22-
import androidx.annotation.Nullable;
23-
import androidx.annotation.VisibleForTesting;
24-
25-
import kotlin.Unit;
26-
import kotlin.jvm.functions.Function2;
27-
2825
import java.io.File;
2926
import java.util.Collection;
3027
import java.util.Collections;
@@ -37,6 +34,9 @@
3734
import java.util.concurrent.RejectedExecutionException;
3835
import java.util.regex.Pattern;
3936

37+
import kotlin.Unit;
38+
import kotlin.jvm.functions.Function2;
39+
4040
/**
4141
* A Bugsnag Client instance allows you to use Bugsnag in your Android app.
4242
* Typically you'd instead use the static access provided in the Bugsnag class.
@@ -383,23 +383,23 @@ public Unit invoke(String oldOrientation, String newOrientation) {
383383
return null;
384384
}
385385
}, new Function2<Boolean, Integer, Unit>() {
386-
@Override
386+
@Override
387387
public Unit invoke(Boolean isLowMemory, Integer memoryTrimLevel) {
388-
memoryTrimState.setLowMemory(Boolean.TRUE.equals(isLowMemory));
389-
if (memoryTrimState.updateMemoryTrimLevel(memoryTrimLevel)) {
390-
leaveAutoBreadcrumb(
391-
"Trim Memory",
392-
BreadcrumbType.STATE,
393-
Collections.<String, Object>singletonMap(
388+
memoryTrimState.setLowMemory(Boolean.TRUE.equals(isLowMemory));
389+
if (memoryTrimState.updateMemoryTrimLevel(memoryTrimLevel)) {
390+
leaveAutoBreadcrumb(
391+
"Trim Memory",
392+
BreadcrumbType.STATE,
393+
Collections.<String, Object>singletonMap(
394394
"trimLevel", memoryTrimState.getTrimLevelDescription()
395395
)
396-
);
397-
}
398-
399-
memoryTrimState.emitObservableEvent();
400-
return null;
401-
}
396+
);
402397
}
398+
399+
memoryTrimState.emitObservableEvent();
400+
return null;
401+
}
402+
}
403403
));
404404
}
405405

@@ -536,7 +536,7 @@ public boolean resumeSession() {
536536
/**
537537
* Bugsnag uses the concept of "contexts" to help display and group your errors. Contexts
538538
* represent what was happening in your application at the time an error occurs.
539-
*
539+
* <p>
540540
* In an android app the "context" is automatically set as the foreground Activity.
541541
* If you would like to set this value manually, you should alter this property.
542542
*/
@@ -548,7 +548,7 @@ public String getContext() {
548548
/**
549549
* Bugsnag uses the concept of "contexts" to help display and group your errors. Contexts
550550
* represent what was happening in your application at the time an error occurs.
551-
*
551+
* <p>
552552
* In an android app the "context" is automatically set as the foreground Activity.
553553
* If you would like to set this value manually, you should alter this property.
554554
*/
@@ -603,15 +603,15 @@ public User getUser() {
603603
/**
604604
* Add a "on error" callback, to execute code at the point where an error report is
605605
* captured in Bugsnag.
606-
*
606+
* <p>
607607
* You can use this to add or modify information attached to an Event
608608
* before it is sent to your dashboard. You can also return
609609
* <code>false</code> from any callback to prevent delivery. "on error"
610610
* callbacks do not run before reports generated in the event
611611
* of immediate app termination from crashes in C/C++ code.
612-
*
612+
* <p>
613613
* For example:
614-
*
614+
* <p>
615615
* Bugsnag.addOnError(new OnErrorCallback() {
616616
* public boolean run(Event event) {
617617
* event.setSeverity(Severity.INFO);
@@ -648,12 +648,12 @@ public void removeOnError(@NonNull OnErrorCallback onError) {
648648
/**
649649
* Add an "on breadcrumb" callback, to execute code before every
650650
* breadcrumb captured by Bugsnag.
651-
*
651+
* <p>
652652
* You can use this to modify breadcrumbs before they are stored by Bugsnag.
653653
* You can also return <code>false</code> from any callback to ignore a breadcrumb.
654-
*
654+
* <p>
655655
* For example:
656-
*
656+
* <p>
657657
* Bugsnag.onBreadcrumb(new OnBreadcrumbCallback() {
658658
* public boolean run(Breadcrumb breadcrumb) {
659659
* return false; // ignore the breadcrumb
@@ -689,12 +689,12 @@ public void removeOnBreadcrumb(@NonNull OnBreadcrumbCallback onBreadcrumb) {
689689
/**
690690
* Add an "on session" callback, to execute code before every
691691
* session captured by Bugsnag.
692-
*
692+
* <p>
693693
* You can use this to modify sessions before they are stored by Bugsnag.
694694
* You can also return <code>false</code> from any callback to ignore a session.
695-
*
695+
* <p>
696696
* For example:
697-
*
697+
* <p>
698698
* Bugsnag.onSession(new OnSessionCallback() {
699699
* public boolean run(Session session) {
700700
* return false; // ignore the session
@@ -747,6 +747,16 @@ public void notify(@NonNull Throwable exc, @Nullable OnErrorCallback onError) {
747747
notify(exc, null, onError);
748748
}
749749

750+
/**
751+
* Notify Bugsnag of a handled exception
752+
*
753+
* @param exc the exception to send to Bugsnag
754+
* @param options the error options
755+
*/
756+
public void notify(@NonNull Throwable exc, @Nullable ErrorOptions options) {
757+
notify(exc, options, null);
758+
}
759+
750760
/**
751761
* Notify Bugsnag of a handled exception
752762
*
@@ -767,7 +777,7 @@ public void notify(
767777
SeverityReason severityReason = SeverityReason.newInstance(REASON_HANDLED_EXCEPTION);
768778
Event event = createEventWithOptions(exc, severityReason, options);
769779
event.setGroupingDiscriminator(getGroupingDiscriminator());
770-
populateAndNotifyAndroidEvent(event,options, onError);
780+
populateAndNotifyAndroidEvent(event, options, onError);
771781
} else {
772782
logNull("notify");
773783
}
@@ -796,33 +806,19 @@ private Event createEventWithOptions(
796806
final FeatureFlags featureFlags = capture == null || capture.getFeatureFlags()
797807
? featureFlagState.getFeatureFlags()
798808
: new FeatureFlags();
799-
final boolean stacktrace = capture == null || capture.getStacktrace();
800-
final boolean threads = capture == null || capture.getThreads();
801-
802-
Event event;
803-
if (options != null || capture != null) {
804-
event = new Event(
805-
exc,
806-
immutableConfig,
807-
severityReason,
808-
metadata,
809-
featureFlags,
810-
stacktrace,
811-
threads,
812-
logger
813-
);
814-
} else {
815-
event = new Event(
816-
exc,
817-
immutableConfig,
818-
severityReason,
819-
metadataState.getMetadata(),
820-
featureFlagState.getFeatureFlags(),
821-
stacktrace,
822-
threads,
823-
logger);
824-
}
825-
return event;
809+
final boolean captureStacktrace = capture == null || capture.getStacktrace();
810+
final boolean captureThreads = capture == null || capture.getThreads();
811+
812+
return new Event(
813+
exc,
814+
immutableConfig,
815+
severityReason,
816+
metadata,
817+
featureFlags,
818+
captureStacktrace,
819+
captureThreads,
820+
logger
821+
);
826822
}
827823

828824
private Metadata captureSelectedMetadata(@Nullable Set<String> metadata) {
@@ -847,7 +843,7 @@ private Metadata captureSelectedMetadata(@Nullable Set<String> metadata) {
847843

848844
/**
849845
* Caches an error then attempts to notify.
850-
*
846+
* <p>
851847
* Should only ever be called from the {@link ExceptionHandler}.
852848
*/
853849
void notifyUnhandledException(@NonNull Throwable exc, Metadata metadata,
@@ -881,7 +877,7 @@ void populateAndNotifyAndroidEvent(@NonNull Event event,
881877
void populateAndNotifyAndroidEvent(@NonNull Event event,
882878
@Nullable ErrorOptions options,
883879
@Nullable OnErrorCallback onError
884-
) {
880+
) {
885881
populateDeviceAndAppData(event);
886882

887883
if (options == null) {
@@ -996,7 +992,7 @@ void notifyInternal(@NonNull Event event,
996992
* Returns the current buffer of breadcrumbs that will be sent with captured events. This
997993
* ordered list represents the most recent breadcrumbs to be captured up to the limit
998994
* set in {@link Configuration#getMaxBreadcrumbs()}.
999-
*
995+
* <p>
1000996
* The returned collection is readonly and mutating the list will cause no effect on the
1001997
* Client's state. If you wish to alter the breadcrumbs collected by the Client then you should
1002998
* use {@link Configuration#setEnabledBreadcrumbTypes(Set)} and
@@ -1226,7 +1222,7 @@ public void clearFeatureFlags() {
12261222

12271223
/**
12281224
* Retrieves information about the last launch of the application, if it has been run before.
1229-
*
1225+
* <p>
12301226
* For example, this allows checking whether the app crashed on its last launch, which could
12311227
* be used to perform conditional behaviour to recover from crashes, such as clearing the
12321228
* app data cache.
@@ -1240,7 +1236,7 @@ public LastRunInfo getLastRunInfo() {
12401236
* Informs Bugsnag that the application has finished launching. Once this has been called
12411237
* {@link AppWithState#isLaunching()} will always be false in any new error reports,
12421238
* and synchronous delivery will not be attempted on the next launch for any fatal crashes.
1243-
*
1239+
* <p>
12441240
* By default this method will be called after Bugsnag is initialized when
12451241
* {@link Configuration#getLaunchDurationMillis()} has elapsed. Invoking this method manually
12461242
* has precedence over the value supplied via the launchDurationMillis configuration option.

0 commit comments

Comments
 (0)