Skip to content

Commit e665b6e

Browse files
committed
fix: return null when error type is null
1 parent 94703eb commit e665b6e

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
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; we default to INTERNAL.
123-
return ErrorType.INTERNAL.toString();
122+
// No information about the error; This attribute should not be recorded.
123+
return null;
124124
}
125125

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

129129
// 2. Attempt to extract specific error type from the main exception
130130
String specificError = extractSpecificErrorType(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 getRealCause(Throwable t) {
146+
private static Throwable unwrapError(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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ class ErrorTypeUtilTest {
5454

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

6160
@Test

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

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

0 commit comments

Comments
 (0)