Skip to content

Commit 714dbaa

Browse files
jbzhurbruno-garcia
authored andcommitted
Fixed loosing of interruption status in EventBuilder. (#799)
1 parent 722a59d commit 714dbaa

File tree

24 files changed

+74
-61
lines changed

24 files changed

+74
-61
lines changed

sentry-android/src/main/java/io/sentry/android/event/helper/AndroidEventBuilderHelper.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.content.IntentFilter;
77
import android.content.pm.ApplicationInfo;
88
import android.content.pm.PackageInfo;
9+
import android.content.pm.PackageManager;
910
import android.content.res.AssetManager;
1011
import android.net.ConnectivityManager;
1112
import android.net.NetworkInfo;
@@ -168,7 +169,7 @@ protected static String[] getProGuardUuids(Context ctx) {
168169
}
169170
} catch (FileNotFoundException e) {
170171
Log.d(TAG, "Proguard UUIDs file not found.");
171-
} catch (Exception e) {
172+
} catch (IOException | RuntimeException e) {
172173
Log.e(TAG, "Error getting Proguard UUIDs.", e);
173174
}
174175

@@ -185,7 +186,7 @@ protected static String[] getProGuardUuids(Context ctx) {
185186
protected static PackageInfo getPackageInfo(Context ctx) {
186187
try {
187188
return ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0);
188-
} catch (Exception e) {
189+
} catch (PackageManager.NameNotFoundException | RuntimeException e) {
189190
Log.e(TAG, "Error getting package info.", e);
190191
return null;
191192
}
@@ -200,7 +201,7 @@ protected static PackageInfo getPackageInfo(Context ctx) {
200201
protected static String getFamily() {
201202
try {
202203
return Build.MODEL.split(" ")[0];
203-
} catch (Exception e) {
204+
} catch (RuntimeException e) {
204205
Log.e(TAG, "Error getting device family.", e);
205206
return null;
206207
}
@@ -221,7 +222,7 @@ protected static Boolean isEmulator() {
221222
|| Build.MANUFACTURER.contains("Genymotion")
222223
|| (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
223224
|| "google_sdk".equals(Build.PRODUCT);
224-
} catch (Exception e) {
225+
} catch (RuntimeException e) {
225226
Log.e(TAG, "Error checking whether application is running in an emulator.", e);
226227
return null;
227228
}
@@ -239,7 +240,7 @@ protected static ActivityManager.MemoryInfo getMemInfo(Context ctx) {
239240
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
240241
actManager.getMemoryInfo(memInfo);
241242
return memInfo;
242-
} catch (Exception e) {
243+
} catch (RuntimeException e) {
243244
Log.e(TAG, "Error getting MemoryInfo.", e);
244245
return null;
245246
}
@@ -266,7 +267,7 @@ protected static String getOrientation(Context ctx) {
266267
break;
267268
}
268269
return o;
269-
} catch (Exception e) {
270+
} catch (RuntimeException e) {
270271
Log.e(TAG, "Error getting device orientation.", e);
271272
return null;
272273
}
@@ -297,7 +298,7 @@ protected static Float getBatteryLevel(Context ctx) {
297298
// CHECKSTYLE.ON: MagicNumber
298299

299300
return ((float) level / (float) scale) * percentMultiplier;
300-
} catch (Exception e) {
301+
} catch (RuntimeException e) {
301302
Log.e(TAG, "Error getting device battery level.", e);
302303
return null;
303304
}
@@ -318,7 +319,7 @@ protected static Boolean isCharging(Context ctx) {
318319

319320
int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
320321
return plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB;
321-
} catch (Exception e) {
322+
} catch (RuntimeException e) {
322323
Log.e(TAG, "Error getting device charging state.", e);
323324
return null;
324325
}
@@ -343,7 +344,7 @@ protected static String getKernelVersion() {
343344

344345
br = new BufferedReader(new FileReader(file));
345346
return br.readLine();
346-
} catch (Exception e) {
347+
} catch (IOException | RuntimeException e) {
347348
Log.e(TAG, errorMsg, e);
348349
} finally {
349350
if (br != null) {
@@ -392,7 +393,7 @@ protected static Boolean isRooted() {
392393
if (new File(probableRootPath).exists()) {
393394
return true;
394395
}
395-
} catch (Exception e) {
396+
} catch (RuntimeException e) {
396397
Log.e(TAG, "Exception while attempting to detect whether the device is rooted", e);
397398
}
398399
}
@@ -417,7 +418,7 @@ protected static Long getUnusedInternalStorage() {
417418
long blockSize = stat.getBlockSize();
418419
long availableBlocks = stat.getAvailableBlocks();
419420
return availableBlocks * blockSize;
420-
} catch (Exception e) {
421+
} catch (RuntimeException e) {
421422
Log.e(TAG, "Error getting unused internal storage amount.", e);
422423
return null;
423424
}
@@ -435,7 +436,7 @@ protected static Long getTotalInternalStorage() {
435436
long blockSize = stat.getBlockSize();
436437
long totalBlocks = stat.getBlockCount();
437438
return totalBlocks * blockSize;
438-
} catch (Exception e) {
439+
} catch (RuntimeException e) {
439440
Log.e(TAG, "Error getting total internal storage amount.", e);
440441
return null;
441442
}
@@ -457,7 +458,7 @@ protected static Long getUnusedExternalStorage() {
457458
long availableBlocks = stat.getAvailableBlocks();
458459
return availableBlocks * blockSize;
459460
}
460-
} catch (Exception e) {
461+
} catch (RuntimeException e) {
461462
Log.e(TAG, "Error getting unused external storage amount.", e);
462463
}
463464

@@ -480,7 +481,7 @@ protected static Long getTotalExternalStorage() {
480481
long totalBlocks = stat.getBlockCount();
481482
return totalBlocks * blockSize;
482483
}
483-
} catch (Exception e) {
484+
} catch (RuntimeException e) {
484485
Log.e(TAG, "Error getting total external storage amount.", e);
485486
}
486487

@@ -496,7 +497,7 @@ protected static Long getTotalExternalStorage() {
496497
protected static DisplayMetrics getDisplayMetrics(Context ctx) {
497498
try {
498499
return ctx.getResources().getDisplayMetrics();
499-
} catch (Exception e) {
500+
} catch (RuntimeException e) {
500501
Log.e(TAG, "Error getting DisplayMetrics.", e);
501502
return null;
502503
}
@@ -530,7 +531,7 @@ protected static String getApplicationName(Context ctx) {
530531
} else {
531532
return ctx.getString(stringId);
532533
}
533-
} catch (Exception e) {
534+
} catch (RuntimeException e) {
534535
Log.e(TAG, "Error getting application name.", e);
535536
}
536537

sentry-appengine/src/main/java/io/sentry/appengine/connection/AppEngineAsyncConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void run() {
151151
return;
152152
}
153153
connection.actualConnection.send(event);
154-
} catch (Exception e) {
154+
} catch (RuntimeException e) {
155155
logger.error("An exception occurred while sending the event to Sentry.", e);
156156
} finally {
157157
SentryEnvironment.stopManagingThread();

sentry-appengine/src/test/java/io/sentry/appengine/connection/AppEngineAsyncConnectionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public TaskHandle answer(InvocationOnMock invocation) throws Throwable {
113113
TaskOptions taskOptions = invocation.getArgument(0);
114114
try {
115115
extractDeferredTask(taskOptions).run();
116-
} catch (Exception e) {
116+
} catch (RuntimeException e) {
117117
throw new RuntimeException("Couldn't extract the task", e);
118118
}
119119
return null;

sentry-log4j/src/main/java/io/sentry/log4j/SentryAppender.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected void append(LoggingEvent loggingEvent) {
8383
try {
8484
EventBuilder eventBuilder = createEventBuilder(loggingEvent);
8585
Sentry.capture(eventBuilder);
86-
} catch (Exception e) {
86+
} catch (RuntimeException e) {
8787
getErrorHandler().error("An exception occurred while creating a new event in Sentry", e,
8888
ErrorCode.WRITE_FAILURE);
8989
} finally {
@@ -151,7 +151,7 @@ public void close() {
151151
}
152152
this.closed = true;
153153
Sentry.close();
154-
} catch (Exception e) {
154+
} catch (RuntimeException e) {
155155
getErrorHandler().error("An exception occurred while closing the Sentry connection", e,
156156
ErrorCode.CLOSE_FAILURE);
157157
} finally {

sentry-log4j2/src/main/java/io/sentry/log4j2/SentryAppender.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void append(LogEvent logEvent) {
131131
try {
132132
EventBuilder eventBuilder = createEventBuilder(logEvent);
133133
Sentry.capture(eventBuilder);
134-
} catch (Exception e) {
134+
} catch (RuntimeException e) {
135135
error("An exception occurred while creating a new event in Sentry", logEvent, e);
136136
} finally {
137137
SentryEnvironment.stopManagingThread();
@@ -201,7 +201,7 @@ public void stop() {
201201
}
202202
super.stop();
203203
Sentry.close();
204-
} catch (Exception e) {
204+
} catch (RuntimeException e) {
205205
error("An exception occurred while closing the Sentry connection", e);
206206
} finally {
207207
SentryEnvironment.stopManagingThread();

sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected void append(ILoggingEvent iLoggingEvent) {
113113

114114
EventBuilder eventBuilder = createEventBuilder(iLoggingEvent);
115115
Sentry.capture(eventBuilder);
116-
} catch (Exception e) {
116+
} catch (RuntimeException e) {
117117
addError("An exception occurred while creating a new event in Sentry", e);
118118
} finally {
119119
SentryEnvironment.stopManagingThread();
@@ -301,7 +301,7 @@ public void stop() {
301301
}
302302
super.stop();
303303
Sentry.close();
304-
} catch (Exception e) {
304+
} catch (RuntimeException e) {
305305
addError("An exception occurred while closing the Sentry connection", e);
306306
} finally {
307307
SentryEnvironment.stopManagingThread();

sentry/src/main/java/io/sentry/DefaultSentryClientFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public SentryClient createSentryClient(Dsn dsn) {
275275
}
276276
sentryClient.addBuilderHelper(new ContextBuilderHelper(sentryClient));
277277
return configureSentryClient(sentryClient, dsn);
278-
} catch (Exception e) {
278+
} catch (RuntimeException e) {
279279
logger.error("Failed to initialize sentry, falling back to no-op client", e);
280280
return new SentryClient(new NoopConnection(), new ThreadLocalContextManager());
281281
}

sentry/src/main/java/io/sentry/SentryClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void sendEvent(Event event) {
139139
connection.send(event);
140140
} catch (LockedDownException | TooManyRequestsException e) {
141141
logger.debug("Dropping an Event due to lockdown: " + event);
142-
} catch (Exception e) {
142+
} catch (RuntimeException e) {
143143
logger.error("An exception occurred while sending the event to Sentry.", e);
144144
} finally {
145145
getContext().setLastEventId(event.getId());

sentry/src/main/java/io/sentry/SentryOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private static String resolveDsn(Lookup lookup, @Nullable String dsn) {
207207
}
208208

209209
return dsn;
210-
} catch (Exception e) {
210+
} catch (RuntimeException e) {
211211
logger.error("Error creating valid DSN from: '{}'.", dsn, e);
212212
throw e;
213213
}

sentry/src/main/java/io/sentry/SentryUncaughtExceptionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void uncaughtException(Thread thread, Throwable thrown) {
5353

5454
try {
5555
Sentry.capture(eventBuilder);
56-
} catch (Exception e) {
56+
} catch (RuntimeException e) {
5757
logger.error("Error sending uncaught exception to Sentry.", e);
5858
}
5959
}

0 commit comments

Comments
 (0)