Nachbearbeitung: Konfigurationslade- und Parsefehler einheitlich
klassifiziert
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
||||
package de.gecheckt.pdf.umbenenner.adapter.out.configuration;
|
||||
|
||||
/**
|
||||
* Exception thrown when configuration loading or parsing fails.
|
||||
* <p>
|
||||
* This exception covers all failures related to loading, reading, or parsing the configuration,
|
||||
* including:
|
||||
* <ul>
|
||||
* <li>I/O failures when reading the configuration file</li>
|
||||
* <li>Missing required properties</li>
|
||||
* <li>Invalid property values (e.g., unparseable integers, invalid URIs)</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* This is a controlled failure mode that prevents processing from starting.
|
||||
*/
|
||||
public class ConfigurationLoadingException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Creates the exception with an error message.
|
||||
*
|
||||
* @param message the error message describing what failed during configuration loading
|
||||
*/
|
||||
public ConfigurationLoadingException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the exception with an error message and a cause.
|
||||
*
|
||||
* @param message the error message describing what failed during configuration loading
|
||||
* @param cause the underlying exception that caused the configuration failure
|
||||
*/
|
||||
public ConfigurationLoadingException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -93,7 +93,7 @@ public class PropertiesConfigurationPortAdapter implements ConfigurationPort {
|
||||
String escapedContent = escapeBackslashes(content);
|
||||
props.load(new StringReader(escapedContent));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to load configuration from " + configFilePath, e);
|
||||
throw new ConfigurationLoadingException("Failed to load configuration from " + configFilePath, e);
|
||||
}
|
||||
return props;
|
||||
}
|
||||
@@ -137,7 +137,7 @@ public class PropertiesConfigurationPortAdapter implements ConfigurationPort {
|
||||
private String getRequiredProperty(Properties props, String key) {
|
||||
String value = props.getProperty(key);
|
||||
if (value == null || value.isBlank()) {
|
||||
throw new IllegalStateException("Required property missing: " + key);
|
||||
throw new ConfigurationLoadingException("Required property missing: " + key);
|
||||
}
|
||||
return normalizePath(value.trim());
|
||||
}
|
||||
@@ -161,7 +161,7 @@ public class PropertiesConfigurationPortAdapter implements ConfigurationPort {
|
||||
try {
|
||||
return Integer.parseInt(value.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalStateException("Invalid integer value for property: " + value, e);
|
||||
throw new ConfigurationLoadingException("Invalid integer value for property: " + value, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ public class PropertiesConfigurationPortAdapter implements ConfigurationPort {
|
||||
try {
|
||||
return new URI(value.trim());
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalStateException("Invalid URI value for property: " + value, e);
|
||||
throw new ConfigurationLoadingException("Invalid URI value for property: " + value, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user