From 3a6923d980d543af045a7a9fa9bbfce9cd398980 Mon Sep 17 00:00:00 2001 From: Tommy Ludwig <8924140+shakuzen@users.noreply.github.com> Date: Wed, 31 Jan 2024 13:44:11 +0900 Subject: [PATCH] Polish Polish gh-4595 --- .../io/micrometer/registry/otlp/OtlpConfig.java | 3 ++- .../micrometer/registry/otlp/OtlpConfigTest.java | 5 +++-- .../config/InvalidConfigurationException.java | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpConfig.java b/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpConfig.java index d6910e5a53..a735d097e9 100644 --- a/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpConfig.java +++ b/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpConfig.java @@ -15,6 +15,7 @@ */ package io.micrometer.registry.otlp; +import io.micrometer.core.instrument.config.InvalidConfigurationException; import io.micrometer.core.instrument.config.validate.Validated; import io.micrometer.core.instrument.push.PushRegistryConfig; @@ -138,7 +139,7 @@ default Map headers() { headersString = URLDecoder.decode(headersString, "UTF-8"); } catch (Exception e) { - throw new IllegalArgumentException("Cannot decode header value: " + headersString, e); + throw new InvalidConfigurationException("Cannot URL decode header value: " + headersString, e); } } diff --git a/implementations/micrometer-registry-otlp/src/test/java/io/micrometer/registry/otlp/OtlpConfigTest.java b/implementations/micrometer-registry-otlp/src/test/java/io/micrometer/registry/otlp/OtlpConfigTest.java index 5ec6d688e7..b45ae85391 100644 --- a/implementations/micrometer-registry-otlp/src/test/java/io/micrometer/registry/otlp/OtlpConfigTest.java +++ b/implementations/micrometer-registry-otlp/src/test/java/io/micrometer/registry/otlp/OtlpConfigTest.java @@ -15,6 +15,7 @@ */ package io.micrometer.registry.otlp; +import io.micrometer.core.instrument.config.InvalidConfigurationException; import org.junit.jupiter.api.Test; import java.util.Collections; @@ -73,8 +74,8 @@ void headersUseEnvVarWhenConfigNotSet() throws Exception { void headersDecodingError() throws Exception { OtlpConfig config = k -> null; withEnvironmentVariable("OTEL_EXPORTER_OTLP_HEADERS", "header2=%-1").execute(() -> { - assertThatThrownBy(config::headers).isInstanceOf(IllegalArgumentException.class) - .hasMessage("Cannot decode header value: header2=%-1,"); + assertThatThrownBy(config::headers).isInstanceOf(InvalidConfigurationException.class) + .hasMessage("Cannot URL decode header value: header2=%-1,"); }); } diff --git a/micrometer-core/src/main/java/io/micrometer/core/instrument/config/InvalidConfigurationException.java b/micrometer-core/src/main/java/io/micrometer/core/instrument/config/InvalidConfigurationException.java index 3369193b43..69e4d7700b 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/instrument/config/InvalidConfigurationException.java +++ b/micrometer-core/src/main/java/io/micrometer/core/instrument/config/InvalidConfigurationException.java @@ -21,6 +21,20 @@ */ public class InvalidConfigurationException extends IllegalStateException { + /** + * Construct an exception indication invalid configuration with the specified detail + * message and cause. + * @param message the detail message (which is saved for later retrieval by the + * {@link Throwable#getMessage()} method). + * @param cause the cause (which is saved for later retrieval by the + * {@link Throwable#getCause()} method). (A {@code null} value is permitted, and + * indicates that the cause is nonexistent or unknown.) + * @since 1.11.9 + */ + public InvalidConfigurationException(String message, Throwable cause) { + super(message, cause); + } + public InvalidConfigurationException(String s) { super(s); }