Skip to content

Commit 7b27f30

Browse files
committed
Revert "fix: return null when error type is null"
This reverts commit e665b6e.
1 parent 537cd7e commit 7b27f30

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ErrorTypeUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ enum ErrorType {
119119
// Requirement source: go/clo:product-requirements-v1
120120
public static String extractErrorType(@Nullable Throwable error) {
121121
if (error == null) {
122-
// No information about the error; This attribute should not be recorded.
123-
return null;
122+
// No information about the error; we default to INTERNAL.
123+
return ErrorType.INTERNAL.toString();
124124
}
125125

126126
// 1. Unwrap standard wrapper exceptions if present
127-
Throwable realError = unwrapError(error);
127+
Throwable realError = getRealCause(error);
128128

129129
// 2. Attempt to extract specific error type from the main exception
130130
String specificError = extractKnownErrorType(realError);
@@ -143,7 +143,7 @@ public static String extractErrorType(@Nullable Throwable error) {
143143
}
144144

145145
/** Unwraps standard execution wrappers to find the real cause. */
146-
private static Throwable unwrapError(Throwable t) {
146+
private static Throwable getRealCause(Throwable t) {
147147
if (t.getCause() == null) {
148148
return t;
149149
}

sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ErrorTypeUtilTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ class ErrorTypeUtilTest {
5454

5555
@Test
5656
void testExtractErrorType_null() {
57-
assertThat(ErrorTypeUtil.extractErrorType(null)).isNull();
57+
assertThat(ErrorTypeUtil.extractErrorType(null))
58+
.isEqualTo(ErrorTypeUtil.ErrorType.INTERNAL.toString());
5859
}
5960

6061
@Test

sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/SpanTracerTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,10 @@ void testAttemptFailed_internalFallback_nullError() {
439439
// For an anonymous inner class Throwable, getSimpleName() is empty string,
440440
// which triggers the
441441
// fallback
442-
verify(span, never())
443-
.setAttribute(eq(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), anyString());
442+
verify(span)
443+
.setAttribute(
444+
ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE,
445+
ErrorTypeUtil.ErrorType.INTERNAL.toString());
444446
verify(span).end();
445447
}
446448

0 commit comments

Comments
 (0)