Skip to content

Commit 160367a

Browse files
committed
refactor error handling for daemon mode
1 parent b84f876 commit 160367a

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

src/main/java/uk/ac/ed/epcc/ctp_anon_cli/Program.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,26 @@ public static void main(String[] args) throws ParseException {
107107
String[] filePairSplit = line.split(" ");
108108

109109
if (filePairSplit.length != 2) {
110-
System.err.println("Expected two file paths");
110+
System.out.println("Expected two file paths");
111111
continue;
112112
}
113113

114+
File inFile = new File(filePairSplit[0]);
115+
File outFile = new File(filePairSplit[1]);
116+
114117
try {
115-
File inFile = new File(filePairSplit[0]);
116-
File outFile = new File(filePairSplit[1]);
117118

118119
outFile = ValidateFilePair(inFile, outFile);
119120

120121
anonymizer.anonymize(inFile, outFile);
121122
} catch (Exception e) {
122-
System.err.println(e.getMessage());
123+
System.out.println("[" + inFile + ":" + outFile + "] " + e.getMessage());
123124
continue;
124125
}
125126
}
126127
}
127128
}
128129

129-
int rc = 0;
130-
131130
if (
132131
files.size() == 2 &&
133132
!files.get(0).contains(":") &&
@@ -143,9 +142,14 @@ public static void main(String[] args) throws ParseException {
143142
System.exit(1);
144143
}
145144

146-
rc = anonymizer.anonymize(inFile, outFile);
145+
try {
146+
anonymizer.anonymize(inFile, outFile);
147+
} catch (Exception e) {
148+
System.err.println(e.getMessage());
149+
System.exit(1);
150+
}
147151

148-
System.exit(rc);
152+
System.exit(0);
149153
}
150154

151155
List<File> filePairsToProcess = new ArrayList<File>();
@@ -183,14 +187,18 @@ public static void main(String[] args) throws ParseException {
183187
}
184188

185189
for (int i = 0; i < filePairsToProcess.size(); i += 2) {
186-
rc =
190+
try {
187191
anonymizer.anonymize(
188192
filePairsToProcess.get(i),
189193
filePairsToProcess.get(i + 1)
190194
);
195+
} catch (Exception e) {
196+
System.err.println(e.getMessage());
197+
System.exit(1);
198+
}
191199
}
192200

193-
System.exit(rc);
201+
System.exit(0);
194202
}
195203

196204
private static Options AddRequiredOptions(Options options) {

src/main/java/uk/ac/ed/epcc/ctp_anon_cli/SmiCtpProcessor.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,7 @@ public SmiCtpProcessor(
5959
_transcoder.setTransferSyntax(JPEGLossLess);
6060
}
6161

62-
public int anonymize(File inFile, File outFile) {
63-
int rc = 0;
64-
try {
65-
anonymizeImpl(inFile, outFile);
66-
} catch (Exception e) {
67-
System.err.println("[" + inFile + ":" + outFile + "] " + e.getMessage());
68-
rc = 1;
69-
}
70-
return rc;
71-
}
72-
73-
public void anonymizeImpl(File inFile, File outFile) throws Exception {
62+
public void anonymize(File inFile, File outFile) throws Exception {
7463
// NOTE(rkm 2023-12-01) This ensures CTP won't accidentally clobber the input file
7564
if (inFile.canWrite()) {
7665
throw new Exception("Input file was writeable");

0 commit comments

Comments
 (0)