Skip to content

Commit 7ef71c2

Browse files
committed
fix: make extractErrorType nonnull
1 parent c36d985 commit 7ef71c2

File tree

3 files changed

+4
-22
lines changed

3 files changed

+4
-22
lines changed

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.nio.channels.UnresolvedAddressException;
4444
import java.security.GeneralSecurityException;
4545
import java.util.Set;
46+
import javax.annotation.Nonnull;
4647
import javax.annotation.Nullable;
4748
import javax.net.ssl.SSLHandshakeException;
4849

@@ -112,15 +113,10 @@ enum ErrorType {
112113
* </ol>
113114
*
114115
* @param error the Throwable from which to extract the error type string.
115-
* @return a low-cardinality string representing the specific error type, or {@code null} if the
116-
* provided error is {@code null} or non-determined.
116+
* @return a low-cardinality string representing the specific error type
117117
*/
118118
// Requirement source: go/clo:product-requirements-v1
119-
public static String extractErrorType(@Nullable Throwable error) {
120-
if (error == null) {
121-
// No information about the error; return null so the attribute is not recorded.
122-
return null;
123-
}
119+
public static String extractErrorType(@Nonnull Throwable error) {
124120

125121
// 1. Unwrap standard wrapper exceptions if present
126122
Throwable realError = getRealCause(error);

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@
4444

4545
final class ObservabilityUtils {
4646

47-
/**
48-
* Extracts a low-cardinality string representing the specific classification of the error to be
49-
* used in the {@link ObservabilityAttributes#ERROR_TYPE_ATTRIBUTE} attribute. See {@link
50-
* ErrorTypeUtil#extractErrorType} for extended documentation.
51-
*/
52-
static String extractErrorType(@Nullable Throwable error) {
53-
return ErrorTypeUtil.extractErrorType(error);
54-
}
55-
5647
/** Function to extract the status of the error as a canonical code. */
5748
static StatusCode.Code extractStatus(@Nullable Throwable error) {
5849
if (error == null) {
@@ -182,7 +173,7 @@ static Map<String, Object> getResponseAttributes(
182173
}
183174
if (error != null) {
184175
attributes.put(
185-
ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE, ObservabilityUtils.extractErrorType(error));
176+
ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE, ErrorTypeUtil.extractErrorType(error));
186177
attributes.put(ObservabilityAttributes.EXCEPTION_TYPE_ATTRIBUTE, error.getClass().getName());
187178
}
188179
return attributes;

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@
5151

5252
class ErrorTypeUtilTest {
5353

54-
@Test
55-
void testExtractErrorType_null() {
56-
assertThat(ErrorTypeUtil.extractErrorType(null)).isNull();
57-
}
58-
5954
@Test
6055
void testExtractErrorType_apiException_noReason() {
6156
ApiException exception =

0 commit comments

Comments
 (0)