Skip to content

Commit

Permalink
Merge pull request #1859 from bugsnag/PLAT-7516_ThreadType_should_be_…
Browse files Browse the repository at this point in the history
…replaced_by_ErrorType

Replace thread type to error type
  • Loading branch information
lemnik authored Jul 21, 2023
2 parents 8d4dbea + b972d96 commit 6843565
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 66 deletions.
18 changes: 5 additions & 13 deletions bugsnag-android-core/api/bugsnag-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ public final class com/bugsnag/android/ErrorType : java/lang/Enum {
public static final field C Lcom/bugsnag/android/ErrorType;
public static final field DART Lcom/bugsnag/android/ErrorType;
public static final field REACTNATIVEJS Lcom/bugsnag/android/ErrorType;
public static final field UNKNOWN Lcom/bugsnag/android/ErrorType;
public static final fun fromDescriptor (Ljava/lang/String;)Lcom/bugsnag/android/ErrorType;
public static fun valueOf (Ljava/lang/String;)Lcom/bugsnag/android/ErrorType;
public static fun values ()[Lcom/bugsnag/android/ErrorType;
Expand Down Expand Up @@ -759,12 +760,12 @@ public class com/bugsnag/android/Thread : com/bugsnag/android/JsonStream$Streama
public fun getName ()Ljava/lang/String;
public fun getStacktrace ()Ljava/util/List;
public fun getState ()Lcom/bugsnag/android/Thread$State;
public fun getType ()Lcom/bugsnag/android/ThreadType;
public fun getType ()Lcom/bugsnag/android/ErrorType;
public fun setId (J)V
public fun setName (Ljava/lang/String;)V
public fun setStacktrace (Ljava/util/List;)V
public fun setState (Lcom/bugsnag/android/Thread$State;)V
public fun setType (Lcom/bugsnag/android/ThreadType;)V
public fun setType (Lcom/bugsnag/android/ErrorType;)V
public fun toStream (Lcom/bugsnag/android/JsonStream;)V
}

Expand All @@ -788,13 +789,13 @@ public final class com/bugsnag/android/ThreadInternal : com/bugsnag/android/Json
public final fun getName ()Ljava/lang/String;
public final fun getStacktrace ()Ljava/util/List;
public final fun getState ()Ljava/lang/String;
public final fun getType ()Lcom/bugsnag/android/ThreadType;
public final fun getType ()Lcom/bugsnag/android/ErrorType;
public final fun isErrorReportingThread ()Z
public final fun setId (J)V
public final fun setName (Ljava/lang/String;)V
public final fun setStacktrace (Ljava/util/List;)V
public final fun setState (Ljava/lang/String;)V
public final fun setType (Lcom/bugsnag/android/ThreadType;)V
public final fun setType (Lcom/bugsnag/android/ErrorType;)V
public fun toStream (Lcom/bugsnag/android/JsonStream;)V
}

Expand All @@ -806,15 +807,6 @@ public final class com/bugsnag/android/ThreadSendPolicy : java/lang/Enum {
public static fun values ()[Lcom/bugsnag/android/ThreadSendPolicy;
}

public final class com/bugsnag/android/ThreadType : java/lang/Enum {
public static final field ANDROID Lcom/bugsnag/android/ThreadType;
public static final field C Lcom/bugsnag/android/ThreadType;
public static final field EMPTY Lcom/bugsnag/android/ThreadType;
public static final field REACTNATIVEJS Lcom/bugsnag/android/ThreadType;
public static fun valueOf (Ljava/lang/String;)Lcom/bugsnag/android/ThreadType;
public static fun values ()[Lcom/bugsnag/android/ThreadType;
}

public final class com/bugsnag/android/User : com/bugsnag/android/JsonStream$Streamable {
public fun <init> ()V
public fun <init> (Ljava/lang/String;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ internal class BugsnagEventMapper(
return ThreadInternal(
(thread["id"] as? Number)?.toLong() ?: 0,
thread.readEntry("name"),
ThreadType.fromDescriptor(thread.readEntry("type")) ?: ThreadType.ANDROID,
ErrorType.fromDescriptor(thread.readEntry("type")) ?: ErrorType.ANDROID,
thread["errorReportingThread"] == true,
thread.readEntry("state"),
(thread["stacktrace"] as? List<Map<String, Any?>>)?.let { convertStacktrace(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ package com.bugsnag.android
*/
enum class ErrorType(internal val desc: String) {

/**
* An error with an unknown type or source
*/
UNKNOWN(""),

/**
* An error captured from Android's JVM layer
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Thread implements JsonStream.Streamable {
Thread(
long id,
@NonNull String name,
@NonNull ThreadType type,
@NonNull ErrorType type,
boolean errorReportingThread,
@NonNull Thread.State state,
@NonNull Stacktrace stacktrace,
Expand Down Expand Up @@ -73,7 +73,7 @@ public String getName() {
/**
* Sets the type of thread based on the originating platform (intended for internal use only)
*/
public void setType(@NonNull ThreadType type) {
public void setType(@NonNull ErrorType type) {
if (type != null) {
impl.setType(type);
} else {
Expand All @@ -85,7 +85,7 @@ public void setType(@NonNull ThreadType type) {
* Gets the type of thread based on the originating platform (intended for internal use only)
*/
@NonNull
public ThreadType getType() {
public ErrorType getType() {
return impl.getType();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.io.IOException
class ThreadInternal internal constructor(
var id: Long,
var name: String,
var type: ThreadType,
var type: ErrorType,
val isErrorReportingThread: Boolean,
var state: String,
stacktrace: Stacktrace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ internal class ThreadState @Suppress("LongParameterList") constructor(
return Thread(
thread.id,
thread.name,
ThreadType.ANDROID,
ErrorType.ANDROID,
isErrorThread,
Thread.State.forThread(thread),
stackTrace,
Expand All @@ -117,7 +117,7 @@ internal class ThreadState @Suppress("LongParameterList") constructor(
Thread(
-1,
"[${allThreads.size - maxThreadCount} threads omitted as the maxReportedThreads limit ($maxThreadCount) was exceeded]",
ThreadType.EMPTY,
ErrorType.UNKNOWN,
false,
Thread.State.UNKNOWN,
Stacktrace(arrayOf(StackTraceElement("", "", "-", 0)), projectPackages, logger),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class EventErrorTypeTest {
fun verifyFileNameMixedTypes() {
val config = convertToImmutableConfig(BugsnagTestUtils.generateConfiguration())
val file =
File("1504255147933_0000111122223333aaaabbbbcccc9999_android,c,reactnativejs,dart_my-uuid-123_.json")
File("1504255147933_0000111122223333aaaabbbbcccc9999_,android,c,reactnativejs,dart_my-uuid-123_.json")
val payload = EventPayload(config.apiKey, null, file, Notifier(), config)
assertEquals(ErrorType.values().toSet(), payload.getErrorTypes())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal class EventSerializationTest {
Thread(
5,
"main",
ThreadType.ANDROID,
ErrorType.ANDROID,
true,
Thread.State.RUNNABLE,
stacktrace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void setUp() {
thread = new Thread(
1,
"thread-2",
ThreadType.ANDROID,
ErrorType.ANDROID,
false,
Thread.State.RUNNABLE,
stacktrace,
Expand Down Expand Up @@ -62,16 +62,16 @@ public void nameInvalid() {

@Test
public void typeValid() {
assertEquals(ThreadType.ANDROID, thread.getType());
thread.setType(ThreadType.REACTNATIVEJS);
assertEquals(ThreadType.REACTNATIVEJS, thread.getType());
assertEquals(ErrorType.ANDROID, thread.getType());
thread.setType(ErrorType.REACTNATIVEJS);
assertEquals(ErrorType.REACTNATIVEJS, thread.getType());
}

@Test
public void typeInvalid() {
assertEquals(ThreadType.ANDROID, thread.getType());
assertEquals(ErrorType.ANDROID, thread.getType());
thread.setType(null);
assertEquals(ThreadType.ANDROID, thread.getType());
assertEquals(ErrorType.ANDROID, thread.getType());
assertNotNull(logger.getMsg());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal class ThreadSerializationTest {
val thread = Thread(
24,
"main-one",
ThreadType.ANDROID,
ErrorType.ANDROID,
true,
Thread.State.RUNNABLE,
Stacktrace(
Expand All @@ -42,7 +42,7 @@ internal class ThreadSerializationTest {
val thread1 = Thread(
24,
"main-one",
ThreadType.ANDROID,
ErrorType.ANDROID,
false,
Thread.State.RUNNABLE,
Stacktrace(
Expand Down Expand Up @@ -76,7 +76,7 @@ internal class ThreadSerializationTest {
return Thread(
24,
"main-one",
ThreadType.ANDROID,
ErrorType.ANDROID,
true,
Thread.State.RUNNABLE,
trace,
Expand All @@ -99,7 +99,7 @@ internal class ThreadSerializationTest {
return Thread(
24,
"main-one",
ThreadType.ANDROID,
ErrorType.ANDROID,
false,
Thread.State.RUNNABLE,
trace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Thread deserialize(Map<String, Object> map) {
return new Thread(
MapUtils.<Number>getOrThrow(map, "id").longValue(),
MapUtils.<String>getOrThrow(map, "name"),
ThreadType.valueOf(type.toUpperCase(Locale.US)),
ErrorType.valueOf(type.toUpperCase(Locale.US)),
errorReportingThread,
Thread.State.byDescriptor(MapUtils.<String>getOrThrow(map, "state")),
new Stacktrace(frames),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ThreadDeserializerTest {
fun deserialize() {
val thread = ThreadDeserializer(StackframeDeserializer(), object : Logger {}).deserialize(map)
assertEquals(52, thread.id)
assertEquals(ThreadType.REACTNATIVEJS, thread.type)
assertEquals(ErrorType.REACTNATIVEJS, thread.type)
assertEquals("thread-worker-02", thread.name)
assertTrue(thread.errorReportingThread)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void setup() {
Stackframe stackframe = new Stackframe("foo()", "Bar.kt", 55, true);
List<Stackframe> frames = Collections.singletonList(stackframe);
Stacktrace stacktrace = new Stacktrace(frames);
thread = new Thread(1, "fake-thread", ThreadType.ANDROID,
thread = new Thread(1, "fake-thread", ErrorType.ANDROID,
true, Thread.State.RUNNABLE, stacktrace, NoopLogger.INSTANCE);
}

Expand Down

0 comments on commit 6843565

Please sign in to comment.