Skip to content

Commit a532554

Browse files
committed
Address #394: only complain about exceptions with ending PC/SC sessions in verbose mode
1 parent 07c7f89 commit a532554

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

tool/src/main/java/pro/javacard/gptool/GPTool.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,29 +183,25 @@ public static void main(String[] argv) {
183183
ret = new GPTool().run(CardBIBO.wrap(c), argv);
184184
} catch (IllegalArgumentException e) {
185185
System.err.println("Invalid argument: " + e.getMessage());
186-
if (isTrace)
187-
e.printStackTrace();
186+
trace(e);
188187
} catch (Exception e) {
189188
System.err.println("Error: " + e.getMessage());
190-
if (isTrace)
191-
e.printStackTrace();
189+
trace(e);
192190
} finally {
193191
if (c != null) {
194192
if (transact) {
195193
try {
196194
c.endExclusive();
197195
} catch (CardException e) {
198-
System.err.println("Exception when ending card transaction: " + e.getMessage());
199-
if (isTrace)
200-
e.printStackTrace();
196+
verbose("Exception when ending card transaction: " + e.getMessage());
197+
trace(e);
201198
}
202199
}
203200
try {
204201
c.disconnect(resetOnDisconnect);
205202
} catch (CardException e) {
206-
System.err.println("Exception when disconnecting card: " + e.getMessage());
207-
if (isTrace)
208-
e.printStackTrace();
203+
verbose("Exception when disconnecting card: " + e.getMessage());
204+
trace(e);
209205
}
210206
}
211207
}
@@ -910,8 +906,7 @@ else if (keyver >= 0x30 && keyver <= 0x3F)
910906
return 0;
911907
} catch (IOException e) {
912908
System.err.println("ERROR: " + e.getMessage());
913-
if (isTrace)
914-
e.printStackTrace();
909+
trace(e);
915910
} catch (ReceiptVerifier.ReceiptVerificationException e) {
916911
/// XXX: refactor
917912
System.err.println("WARNING: Operation completed, but receipt verification failed");
@@ -1185,9 +1180,15 @@ private static boolean needsAuthentication(OptionSet args) {
11851180
return Arrays.stream(yes).anyMatch(args::has);
11861181
}
11871182

1188-
private void verbose(String s) {
1183+
private static void verbose(String s) {
11891184
if (isVerbose) {
11901185
System.out.println("# " + s);
11911186
}
11921187
}
1188+
1189+
private static void trace(Exception e) {
1190+
if (isTrace) {
1191+
e.printStackTrace();
1192+
}
1193+
}
11931194
}

0 commit comments

Comments
 (0)