From c97dd8f5ea5083d661acb2260f86021d0f3349d8 Mon Sep 17 00:00:00 2001 From: Santiago Pericas-Geertsen Date: Mon, 14 Oct 2024 16:51:03 -0400 Subject: [PATCH] Use newly defined exception to report problems while processing meta configuration. This enables special handling of this exception without interfering with any exceptions that may be thrown in custom config sources. --- .../main/java/io/helidon/config/Config.java | 2 +- .../helidon/config/MetaConfigException.java | 44 +++++++++++++++++++ .../java/io/helidon/config/MetaProviders.java | 14 +++--- 3 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 config/config/src/main/java/io/helidon/config/MetaConfigException.java diff --git a/config/config/src/main/java/io/helidon/config/Config.java b/config/config/src/main/java/io/helidon/config/Config.java index bf59b50f5c3..f105ae413d0 100644 --- a/config/config/src/main/java/io/helidon/config/Config.java +++ b/config/config/src/main/java/io/helidon/config/Config.java @@ -1638,7 +1638,7 @@ default Builder metaConfig() { try { MetaConfig.metaConfig() .ifPresent(this::config); - } catch (Exception e) { + } catch (MetaConfigException e) { System.getLogger(getClass().getName()) .log(System.Logger.Level.WARNING, "Failed to load SE meta-configuration," + " please make sure it has correct format.", e); diff --git a/config/config/src/main/java/io/helidon/config/MetaConfigException.java b/config/config/src/main/java/io/helidon/config/MetaConfigException.java new file mode 100644 index 00000000000..af08c95d7c1 --- /dev/null +++ b/config/config/src/main/java/io/helidon/config/MetaConfigException.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.helidon.config; + +/** + * Exception is thrown if problems are found while processing meta config. + */ +public class MetaConfigException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** + * Constructor with the detailed message. + * + * @param message the message + */ + public MetaConfigException(String message) { + super(message); + } + + /** + * Constructor with the detailed message. + * + * @param message the message + * @param cause the cause + */ + public MetaConfigException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/config/config/src/main/java/io/helidon/config/MetaProviders.java b/config/config/src/main/java/io/helidon/config/MetaProviders.java index 1c30190f5a2..9b1abd3fb69 100644 --- a/config/config/src/main/java/io/helidon/config/MetaProviders.java +++ b/config/config/src/main/java/io/helidon/config/MetaProviders.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022 Oracle and/or its affiliates. + * Copyright (c) 2019, 2024 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -113,7 +113,7 @@ static ConfigSource configSource(String type, Config config) { .filter(provider -> provider.supports(type)) .findFirst() .map(provider -> provider.create(type, config)) - .orElseThrow(() -> new IllegalArgumentException("Config source of type " + type + " is not supported." + .orElseThrow(() -> new MetaConfigException("Config source of type " + type + " is not supported." + " Supported types: " + SUPPORTED_CONFIG_SOURCES)); } @@ -122,7 +122,7 @@ static List configSources(String type, Config sourceProperties) { .filter(provider -> provider.supports(type)) .findFirst() .map(provider -> provider.createMulti(type, sourceProperties)) - .orElseThrow(() -> new IllegalArgumentException("Config source of type " + type + " is not supported." + .orElseThrow(() -> new MetaConfigException("Config source of type " + type + " is not supported." + " Supported types: " + SUPPORTED_CONFIG_SOURCES)); } @@ -131,7 +131,7 @@ static OverrideSource overrideSource(String type, Config config) { .filter(provider -> provider.supports(type)) .findFirst() .map(provider -> provider.create(type, config)) - .orElseThrow(() -> new IllegalArgumentException("Config source of type " + type + " is not supported." + .orElseThrow(() -> new MetaConfigException("Config source of type " + type + " is not supported." + " Supported types: " + SUPPORTED_OVERRIDE_SOURCES)); } @@ -140,7 +140,7 @@ static PollingStrategy pollingStrategy(String type, Config config) { .filter(provider -> provider.supports(type)) .findFirst() .map(provider -> provider.create(type, config)) - .orElseThrow(() -> new IllegalArgumentException("Polling strategy of type " + type + " is not supported." + .orElseThrow(() -> new MetaConfigException("Polling strategy of type " + type + " is not supported." + " Supported types: " + SUPPORTED_POLLING_STRATEGIES)); } @@ -149,7 +149,7 @@ static RetryPolicy retryPolicy(String type, Config config) { .filter(provider -> provider.supports(type)) .findFirst() .map(provider -> provider.create(type, config)) - .orElseThrow(() -> new IllegalArgumentException("Retry policy of type " + type + " is not supported." + .orElseThrow(() -> new MetaConfigException("Retry policy of type " + type + " is not supported." + " Supported types: " + SUPPORTED_RETRY_POLICIES)); } @@ -158,7 +158,7 @@ public static ChangeWatcher changeWatcher(String type, Config config) { .filter(provider -> provider.supports(type)) .findFirst() .map(provider -> provider.create(type, config)) - .orElseThrow(() -> new IllegalArgumentException("Change watcher of type " + type + " is not supported." + .orElseThrow(() -> new MetaConfigException("Change watcher of type " + type + " is not supported." + " Supported types: " + SUPPORTED_CHANGE_WATCHERS)); }