From 20878df27bb502231ebbfa5ed5c2a27a7f973720 Mon Sep 17 00:00:00 2001 From: Christoph Pirkl Date: Tue, 2 Jun 2026 08:15:57 +0200 Subject: [PATCH 1/2] #316: Improve error handling for invalid log level --- doc/changes/changes_18.0.2.md | 1 + error_code_config.yml | 2 +- .../adapter/request/LoggingConfiguration.java | 24 ++++++++++++++----- .../request/LoggingConfigurationTest.java | 11 +++++++++ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/doc/changes/changes_18.0.2.md b/doc/changes/changes_18.0.2.md index 00a63aaa..82f9396f 100644 --- a/doc/changes/changes_18.0.2.md +++ b/doc/changes/changes_18.0.2.md @@ -23,6 +23,7 @@ Code name: Improve code quality * #308: Fixed `SqlLimit` so `limit` and `offset` stay non-negative for the full object lifetime by making the node immutable and aligning the validation message with the accepted zero values. * #307: Fixed `PushdownSqlRenderer` so `HASHTYPE` data types include `bytesize` in rendered pushdown SQL JSON. * #312: Fixed logging utility resource and handler lifecycle issues by closing version metadata streams, falling back when the thread context class loader is missing, defaulting absent version properties to `UNKNOWN`, closing replaced root log handlers, and resetting closed remote socket handlers before reuse. +* #316: Fixed `LoggingConfiguration` so invalid `LOG_LEVEL` values now fail with a structured error message that names the invalid value and lists the available log levels. ## Dependency Updates diff --git a/error_code_config.yml b/error_code_config.yml index 3b299927..d3fe2f4b 100644 --- a/error_code_config.yml +++ b/error_code_config.yml @@ -2,4 +2,4 @@ error-tags: VSCOMJAVA: packages: - com.exasol - highest-index: 45 + highest-index: 46 diff --git a/src/main/java/com/exasol/adapter/request/LoggingConfiguration.java b/src/main/java/com/exasol/adapter/request/LoggingConfiguration.java index bf33a30d..725d781f 100644 --- a/src/main/java/com/exasol/adapter/request/LoggingConfiguration.java +++ b/src/main/java/com/exasol/adapter/request/LoggingConfiguration.java @@ -4,9 +4,12 @@ import static com.exasol.adapter.AdapterProperties.LOG_LEVEL_PROPERTY; import java.io.Serializable; +import java.util.List; import java.util.Map; import java.util.logging.Level; +import com.exasol.errorreporting.ExaError; + /** * This class represents the logging configuration set in the request properties */ @@ -14,6 +17,8 @@ public final class LoggingConfiguration implements Serializable { private static final long serialVersionUID = 1930189191497837644L; private static final int DEFAULT_REMOTE_LOGGING_PORT = 3000; private static final Level DEFAULT_LOG_LEVEL = Level.INFO; + private static final List AVAILABLE_LOG_LEVELS = List.of(Level.OFF, Level.SEVERE, Level.WARNING, Level.INFO, Level.CONFIG, Level.FINE, Level.FINER, + Level.FINEST, Level.ALL); /** {@code true} if the adapter should send its log messages to a remote log receiver */ private final boolean logRemotely; /** Name host name where the log receiver listens */ @@ -105,13 +110,20 @@ public static LoggingConfiguration parseFromPropertiesWithDebugAddressGiven(fina } private static Level parseLogLevel(final Map properties) { - final Level level; - if (properties.containsKey(LOG_LEVEL_PROPERTY)) { - level = Level.parse(properties.get(LOG_LEVEL_PROPERTY)); - } else { - level = DEFAULT_LOG_LEVEL; + if (!properties.containsKey(LOG_LEVEL_PROPERTY)) { + return DEFAULT_LOG_LEVEL; + } + final String configuredLogLevel = properties.get(LOG_LEVEL_PROPERTY); + try { + return Level.parse(configuredLogLevel); + } catch (final IllegalArgumentException exception) { + throw new IllegalArgumentException(ExaError.messageBuilder("E-VSCOMJAVA-46") + .message("Invalid value {{log_level_value}} for property {{log_level_property}}.") + .mitigation("Available log levels are: {{available_log_levels}}.") + .parameter("log_level_value", configuredLogLevel) + .parameter("log_level_property", LOG_LEVEL_PROPERTY) + .parameter("available_log_levels", AVAILABLE_LOG_LEVELS).toString(), exception); } - return level; } /** diff --git a/src/test/java/com/exasol/adapter/request/LoggingConfigurationTest.java b/src/test/java/com/exasol/adapter/request/LoggingConfigurationTest.java index b4165f3e..2342b8e3 100644 --- a/src/test/java/com/exasol/adapter/request/LoggingConfigurationTest.java +++ b/src/test/java/com/exasol/adapter/request/LoggingConfigurationTest.java @@ -5,6 +5,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; import java.util.HashMap; @@ -62,6 +63,16 @@ void testGetLogLevel() { assertThat(createLoggingConfiguration(this.properties).getLogLevel(), equalTo(Level.FINEST)); } + @Test + void testInvalidLogLevelThrowsHelpfulException() { + this.properties.put(LOG_LEVEL_PROPERTY, "invalid"); + final IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> createLoggingConfiguration(this.properties)); + assertThat(exception.getMessage(), equalTo( + "E-VSCOMJAVA-46: Invalid value 'invalid' for property 'LOG_LEVEL'. " + + "Available log levels are: [OFF, SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL].")); + } + @Test void testFallBackToLocalLoggingInCaseOfIllegalLoggingPort() { this.properties.put(DEBUG_ADDRESS_PROPERTY, "www.example.org:illegal_non_numeric_port"); From 31126de154ccef95705abc59a73f55e7a7f20acb Mon Sep 17 00:00:00 2001 From: Christoph Pirkl Date: Tue, 2 Jun 2026 10:35:18 +0200 Subject: [PATCH 2/2] Fix duplicate erorr code --- error_code_config.yml | 2 +- .../java/com/exasol/adapter/request/LoggingConfiguration.java | 2 +- .../com/exasol/adapter/request/LoggingConfigurationTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/error_code_config.yml b/error_code_config.yml index d3fe2f4b..9018a22f 100644 --- a/error_code_config.yml +++ b/error_code_config.yml @@ -2,4 +2,4 @@ error-tags: VSCOMJAVA: packages: - com.exasol - highest-index: 46 + highest-index: 47 diff --git a/src/main/java/com/exasol/adapter/request/LoggingConfiguration.java b/src/main/java/com/exasol/adapter/request/LoggingConfiguration.java index 725d781f..4b2aacbb 100644 --- a/src/main/java/com/exasol/adapter/request/LoggingConfiguration.java +++ b/src/main/java/com/exasol/adapter/request/LoggingConfiguration.java @@ -117,7 +117,7 @@ private static Level parseLogLevel(final Map properties) { try { return Level.parse(configuredLogLevel); } catch (final IllegalArgumentException exception) { - throw new IllegalArgumentException(ExaError.messageBuilder("E-VSCOMJAVA-46") + throw new IllegalArgumentException(ExaError.messageBuilder("E-VSCOMJAVA-47") .message("Invalid value {{log_level_value}} for property {{log_level_property}}.") .mitigation("Available log levels are: {{available_log_levels}}.") .parameter("log_level_value", configuredLogLevel) diff --git a/src/test/java/com/exasol/adapter/request/LoggingConfigurationTest.java b/src/test/java/com/exasol/adapter/request/LoggingConfigurationTest.java index 2342b8e3..b1daf9d8 100644 --- a/src/test/java/com/exasol/adapter/request/LoggingConfigurationTest.java +++ b/src/test/java/com/exasol/adapter/request/LoggingConfigurationTest.java @@ -69,7 +69,7 @@ void testInvalidLogLevelThrowsHelpfulException() { final IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> createLoggingConfiguration(this.properties)); assertThat(exception.getMessage(), equalTo( - "E-VSCOMJAVA-46: Invalid value 'invalid' for property 'LOG_LEVEL'. " + "E-VSCOMJAVA-47: Invalid value 'invalid' for property 'LOG_LEVEL'. " + "Available log levels are: [OFF, SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL].")); }