Skip to content

Commit 2eaa281

Browse files
author
Liudmila Molkova
authored
Logging exceptions with context (Azure#45136)
1 parent 536dc97 commit 2eaa281

File tree

105 files changed

+1110
-699
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+1110
-699
lines changed

sdk/clientcore/annotation-processor-test/src/main/java/io/clientcore/annotation/processor/test/ParameterizedMultipleHostServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public HttpBinJSON get(String scheme, String hostPart1, String hostPart2) {
7070
} else if (xmlSerializer.supportsFormat(serializationFormat)) {
7171
deserializedResult = CoreUtils.decodeNetworkResponse(networkResponse.getValue(), xmlSerializer, returnType);
7272
} else {
73-
throw new RuntimeException(new UnsupportedOperationException("None of the provided serializers support the format: " + serializationFormat + "."));
73+
throw new UnsupportedOperationException("None of the provided serializers support the format: " + serializationFormat + ".");
7474
}
7575
return deserializedResult;
7676
}

sdk/clientcore/annotation-processor-test/src/main/java/io/clientcore/annotation/processor/test/SimpleXmlSerializableServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public SimpleXmlSerializable getXml(String contentType) {
128128
} else if (xmlSerializer.supportsFormat(serializationFormat)) {
129129
deserializedResult = CoreUtils.decodeNetworkResponse(networkResponse.getValue(), xmlSerializer, returnType);
130130
} else {
131-
throw new RuntimeException(new UnsupportedOperationException("None of the provided serializers support the format: " + serializationFormat + "."));
131+
throw new UnsupportedOperationException("None of the provided serializers support the format: " + serializationFormat + ".");
132132
}
133133
return deserializedResult;
134134
}
@@ -159,7 +159,7 @@ public SimpleXmlSerializable getInvalidXml(String contentType) {
159159
} else if (xmlSerializer.supportsFormat(serializationFormat)) {
160160
deserializedResult = CoreUtils.decodeNetworkResponse(networkResponse.getValue(), xmlSerializer, returnType);
161161
} else {
162-
throw new RuntimeException(new UnsupportedOperationException("None of the provided serializers support the format: " + serializationFormat + "."));
162+
throw new UnsupportedOperationException("None of the provided serializers support the format: " + serializationFormat + ".");
163163
}
164164
return deserializedResult;
165165
}

sdk/clientcore/annotation-processor-test/src/main/java/io/clientcore/annotation/processor/test/implementation/TestInterfaceClientServiceImpl.java

Lines changed: 49 additions & 49 deletions
Large diffs are not rendered by default.

sdk/clientcore/annotation-processor-test/src/test/java/io/clientcore/annotation/processor/test/TestInterfaceServiceClientGenerationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ protected URI getRequestUri(String requestPath) {
954954
try {
955955
return UriBuilder.parse(getServerUri(isSecure()) + "/" + requestPath).toUri();
956956
} catch (URISyntaxException e) {
957-
throw LOGGER.logThrowableAsError(new RuntimeException(e));
957+
throw LOGGER.throwableAtError().log(e, RuntimeException::new);
958958
}
959959
}
960960

sdk/clientcore/annotation-processor/src/main/java/io/clientcore/annotation/processor/utils/ResponseHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ private static void addSerializationFormatResponseBodyStatements(BlockStmt body)
279279
+ " deserializedResult = CoreUtils.decodeNetworkResponse(networkResponse.getValue(), jsonSerializer, returnType); "
280280
+ "} else if (xmlSerializer.supportsFormat(serializationFormat)) { "
281281
+ " deserializedResult = CoreUtils.decodeNetworkResponse(networkResponse.getValue(), xmlSerializer, returnType); "
282-
+ "} else { " + " throw new RuntimeException(new UnsupportedOperationException("
283-
+ " \"None of the provided serializers support the format: \" + serializationFormat + \".\")); "
282+
+ "} else { " + " throw new UnsupportedOperationException("
283+
+ " \"None of the provided serializers support the format: \" + serializationFormat + \".\"); "
284284
+ "}");
285285
}
286286

sdk/clientcore/core/checkstyle-suppressions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<suppress files="io.clientcore.core.implementation.http.serializer.HttpResponseBodyDecoder.java" checks="com.azure.tools.checkstyle.checks.JavadocThrowsChecks" />
2323
<suppress files="io.clientcore.core.http.client.JdkHttpClientBuilder.java" checks="com.azure.tools.checkstyle.checks.ServiceClientBuilderCheck" />
2424
<suppress files="io.clientcore.core.http.pipeline.HttpInstrumentationPolicy.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
25+
<suppress files="io.clientcore.core.http.pipeline.HttpRetryPolicy.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
2526
<suppress files="io.clientcore.core.implementation.MethodHandleReflectiveInvoker.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
2627
<suppress files="io.clientcore.core.implementation.http.rest.LengthValidatingInputStream.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
2728
<suppress files="io.clientcore.core.implementation.instrumentation.fallback.FallbackInstrumentation.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />

sdk/clientcore/core/spotbugs-exclude.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<Or>
1616
<Class name="io.clientcore.core.credentials.NamedKeyCredential" />
1717
<Class name="io.clientcore.core.credentials.oauth.OAuthTokenRequestContext" />
18+
<Class name="io.clientcore.core.credentials.KeyCredential" />
1819
<Class name="io.clientcore.core.http.models.HttpRange" />
1920
<Class name="io.clientcore.core.http.models.HttpRequest" />
2021
<Class name="io.clientcore.core.http.pipeline.HttpPipelineBuilder" />

sdk/clientcore/core/src/main/java/io/clientcore/core/credentials/KeyCredential.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class KeyCredential {
2828
public KeyCredential(String key) {
2929
Objects.requireNonNull(key, "'key' cannot be null.");
3030
if (key.isEmpty()) {
31-
throw LOGGER.logThrowableAsError(new IllegalArgumentException("'key' cannot be empty."));
31+
throw LOGGER.throwableAtError().log("'key' cannot be empty.", IllegalArgumentException::new);
3232
}
3333

3434
this.key = key;
@@ -54,7 +54,7 @@ public String getKey() {
5454
public KeyCredential update(String key) {
5555
Objects.requireNonNull(key, "'key' cannot be null.");
5656
if (key.isEmpty()) {
57-
throw LOGGER.logThrowableAsError(new IllegalArgumentException("'key' cannot be empty."));
57+
throw LOGGER.throwableAtError().log("'key' cannot be empty.", IllegalArgumentException::new);
5858
}
5959

6060
this.key = key;

sdk/clientcore/core/src/main/java/io/clientcore/core/credentials/NamedKeyCredential.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ private void validateInputParameters(String name, String key) {
9393
Objects.requireNonNull(name, "'name' cannot be null.");
9494
Objects.requireNonNull(key, "'key' cannot be null.");
9595
if (name.isEmpty()) {
96-
throw LOGGER.logThrowableAsError(new IllegalArgumentException("'name' cannot be empty."));
96+
throw LOGGER.throwableAtError().log("'name' cannot be empty.", IllegalArgumentException::new);
9797
}
9898
if (key.isEmpty()) {
99-
throw LOGGER.logThrowableAsError(new IllegalArgumentException("'key' cannot be empty."));
99+
throw LOGGER.throwableAtError().log("'key' cannot be empty.", IllegalArgumentException::new);
100100
}
101101
}
102102
}

sdk/clientcore/core/src/main/java/io/clientcore/core/credentials/oauth/OAuthTokenRequestContext.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ public OAuthTokenRequestContext addScopes(String... scopes) {
8585
Objects.requireNonNull(scopes, "'scopes' cannot be null.");
8686

8787
if (scopes.length == 0) {
88-
throw LOGGER.logThrowableAsError(new IllegalArgumentException("At least one scope must be provided."));
88+
throw LOGGER.throwableAtError().log("At least one scope must be provided.", IllegalArgumentException::new);
8989
}
9090

9191
for (String scope : scopes) {
9292
if (CoreUtils.isNullOrEmpty(scope)) {
93-
throw LOGGER
94-
.logThrowableAsError(new IllegalArgumentException("Scopes cannot contain null or empty values."));
93+
throw LOGGER.throwableAtError()
94+
.log("Scopes cannot contain null or empty values.", IllegalArgumentException::new);
9595
}
9696
}
9797

@@ -136,11 +136,13 @@ public OAuthTokenRequestContext setParams(Map<String, Object> params) {
136136
*/
137137
public OAuthTokenRequestContext setParam(String key, String value) {
138138
if (CoreUtils.isNullOrEmpty(key)) {
139-
throw LOGGER.logThrowableAsError(new IllegalArgumentException("Parameter 'key' cannot be null or empty"));
139+
throw LOGGER.throwableAtError()
140+
.log("Parameter 'key' cannot be null or empty.", IllegalArgumentException::new);
140141
}
141142

142143
if (CoreUtils.isNullOrEmpty(value)) {
143-
throw LOGGER.logThrowableAsError(new IllegalArgumentException("Parameter 'value' cannot be null or empty"));
144+
throw LOGGER.throwableAtError()
145+
.log("Parameter 'value' cannot be null or empty.", IllegalArgumentException::new);
144146
}
145147

146148
if (this.params == null) {

0 commit comments

Comments
 (0)