Skip to content

Commit f1d13c2

Browse files
Remove all thrown exceptions in Dartagnan.main()
Signed-off-by: Hernan Ponce de Leon <hernanl.leon@huawei.com>
1 parent 51d754a commit f1d13c2

2 files changed

Lines changed: 35 additions & 14 deletions

File tree

dartagnan/src/main/java/com/dat3m/dartagnan/Dartagnan.java

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private static Configuration loadConfiguration(String[] args) throws InvalidConf
9898
}
9999

100100

101-
public static void main(String[] args) throws Exception {
101+
public static void main(String[] args) {
102102

103103
initGitInfo();
104104

@@ -109,17 +109,30 @@ public static void main(String[] args) throws Exception {
109109

110110
if (Arrays.asList(args).contains("--version")) {
111111
final MavenXpp3Reader mvnReader = new MavenXpp3Reader();
112-
final FileReader fileReader = new FileReader(System.getenv("DAT3M_HOME") + "/pom.xml");
113-
final String base = mvnReader.read(fileReader).getVersion();
114-
final String version = base.equals(getGitTags()) ? base : String.format("%s (commit %s)", base, getGitId());
115-
System.out.println(version);
112+
final String pomPath = System.getenv("DAT3M_HOME") + "/pom.xml";
113+
try (FileReader fileReader = new FileReader(pomPath)) {
114+
final String base = mvnReader.read(fileReader).getVersion();
115+
final String version = base.equals(getGitTags()) ? base : String.format("%s (commit %s)", base, getGitId());
116+
System.out.println(version);
117+
} catch (Exception e) {
118+
logger.warn("Failed to read version from {}", pomPath, e);
119+
System.exit(UNKNOWN_ERROR.asInt());
120+
}
116121
return;
117122
}
118123

119124
logGitInfo();
120125

121-
final Configuration config = loadConfiguration(args);
122-
final Dartagnan o = new Dartagnan(config);
126+
final Configuration config;
127+
final Dartagnan o;
128+
try {
129+
config = loadConfiguration(args);
130+
o = new Dartagnan(config);
131+
} catch (IOException | InvalidConfigurationException e) {
132+
logger.error(e.getMessage());
133+
System.exit(UNKNOWN_ERROR.asInt());
134+
return;
135+
}
123136

124137
final File fileModel = new File(Arrays.stream(args).filter(a -> a.endsWith(".cat")).findFirst()
125138
.orElseThrow(() -> new IllegalArgumentException("CAT model not given or format not recognized")));
@@ -129,7 +142,13 @@ public static void main(String[] args) throws Exception {
129142
final WitnessGraph witness;
130143
if (o.runValidator()) {
131144
logger.info("Witness path: {}", o.getWitnessPath());
132-
witness = new ParserWitness().parse(new File(o.getWitnessPath()));
145+
try {
146+
witness = new ParserWitness().parse(new File(o.getWitnessPath()));
147+
} catch (IOException e) {
148+
logger.error("Failed to read witness file {}", o.getWitnessPath());
149+
System.exit(WRONG_WITNESS_FILE.asInt());
150+
return;
151+
}
133152
} else {
134153
witness = new WitnessGraph();
135154
}
@@ -220,7 +239,9 @@ private static List<File> getProgramFilesFromArgs(String[] args) {
220239
}
221240
});
222241
if (files.isEmpty()) {
223-
throw new IllegalArgumentException("Path to input program(s) not given or format not recognized");
242+
logger.error("Path to input program(s) not given or format not recognized");
243+
System.exit(UNKNOWN_ERROR.asInt());
244+
224245
}
225246
return files;
226247
}

dartagnan/src/main/java/com/dat3m/dartagnan/utils/GitInfo.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ public class GitInfo {
1515

1616
static Properties properties = new Properties();
1717

18-
public static void initGitInfo() throws IOException {
18+
public static void initGitInfo() {
1919
try (InputStream is = Dartagnan.class.getClassLoader()
2020
.getResourceAsStream("git.properties")) {
21-
if (is == null) {
22-
logger.warn("Failed to load git.properties");
21+
if (is != null) {
22+
properties.load(is);
2323
return;
2424
}
25-
properties.load(is);
26-
}
25+
} catch (IOException e) {}
26+
logger.warn("Failed to load git.properties");
2727
}
2828

2929
public static void logGitInfo() {

0 commit comments

Comments
 (0)