Skip to content

Commit db56685

Browse files
committed
fix: improve error handling in loadVersionFromProperties method
1 parent e60ae89 commit db56685

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/main/java/edu/kit/datamanager/ro_crate/writer/ProvenanceManager.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,21 @@ private ContextualEntity buildRoCrateJavaEntity(
7373
}
7474

7575
private String loadVersionFromProperties() {
76-
try {
77-
URL resource = this.getClass().getResource("/version.properties");
78-
if (resource != null) {
79-
try (InputStream input = resource.openStream()) {
80-
Properties properties = new Properties();
81-
properties.load(input);
82-
return properties.getProperty("version");
83-
}
84-
} else {
85-
System.err.println("Properties file not found!");
86-
return "unknown";
76+
URL resource = this.getClass().getResource("/version.properties");
77+
if (resource == null) {
78+
throw new IllegalStateException("version.properties not found in classpath. This indicates a build configuration issue.");
79+
}
80+
81+
try (InputStream input = resource.openStream()) {
82+
Properties properties = new Properties();
83+
properties.load(input);
84+
String version = properties.getProperty("version");
85+
if (version == null || version.trim().isEmpty()) {
86+
throw new IllegalStateException("No version property found in version.properties");
8787
}
88+
return version.trim();
8889
} catch (IOException e) {
89-
System.err.println("Properties file not found!");
90-
return "unknown";
90+
throw new IllegalStateException("Failed to read version from properties file", e);
9191
}
9292
}
9393
}

0 commit comments

Comments
 (0)