Skip to content

Commit 19b0d92

Browse files
committed
feat: Improve error messages for now-failing-missing-config-file
1 parent 9aae380 commit 19b0d92

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

fed/mosaic-output/src/main/java/org/eclipse/mosaic/fed/output/ambassador/OutputAmbassador.java

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.slf4j.LoggerFactory;
3636

3737
import java.io.IOException;
38+
import java.io.FileNotFoundException;
3839
import java.util.Collection;
3940
import java.util.HashMap;
4041
import java.util.List;
@@ -154,6 +155,8 @@ private Collection<OutputGeneratorLoader> loadConfiguration() {
154155

155156
// do not yet create output generators. This is done when the ambassadors initialize method is called
156157
return generatorLoader.values();
158+
} catch (FileNotFoundException e) {
159+
throw new RuntimeException("Configuration file not found. Consider turning off the output ambassador in scenario_config.json", e);
157160
} catch (InternalFederateException | IllegalArgumentException | IllegalStateException | IOException e) {
158161
throw new RuntimeException(e);
159162
} catch (Exception ex) {

lib/mosaic-utils/src/main/java/org/eclipse/mosaic/lib/util/XmlUtils.java

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.commons.lang3.ObjectUtils;
2525

2626
import java.io.File;
27+
import java.io.FileNotFoundException;
2728
import java.io.IOException;
2829
import java.io.InputStream;
2930
import java.util.stream.Collectors;
@@ -53,6 +54,9 @@ protected Transformer createTransformer() throws ConfigurationException {
5354
}
5455

5556
public static XMLConfiguration readXmlFromFile(File file) throws IOException {
57+
if (!file.exists() || !file.isFile()) {
58+
throw new FileNotFoundException(file.getAbsolutePath() + " cannot be found");
59+
}
5660
final XMLConfiguration configuration = createEmptyConfigurationWithIndentation(DEFAULT_XML_INDENTATION);
5761
try {
5862
new FileHandler(configuration).load(file);

0 commit comments

Comments
 (0)