Skip to content

Commit

Permalink
Use newly defined exception to report problems while processing meta …
Browse files Browse the repository at this point in the history
…configuration. This enables special handling of this exception without interfering with any exceptions that may be thrown in custom config sources.
  • Loading branch information
spericas committed Oct 14, 2024
1 parent 91627f7 commit c97dd8f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
2 changes: 1 addition & 1 deletion config/config/src/main/java/io/helidon/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
14 changes: 7 additions & 7 deletions config/config/src/main/java/io/helidon/config/MetaProviders.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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));
}

Expand All @@ -122,7 +122,7 @@ static List<ConfigSource> 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));
}

Expand All @@ -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));
}

Expand All @@ -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));
}

Expand All @@ -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));
}

Expand All @@ -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));
}

Expand Down

0 comments on commit c97dd8f

Please sign in to comment.