Use System.err for error messages

This commit is contained in:
AsamK 2015-09-15 13:24:27 +02:00
parent 2796fff56d
commit 76a1e8ec2f
2 changed files with 26 additions and 26 deletions

View file

@ -57,7 +57,7 @@ public class Main {
try { try {
m.load(); m.load();
} catch (Exception e) { } catch (Exception e) {
System.out.println("Error loading state file \"" + m.getFileName() + "\": " + e.getMessage()); System.err.println("Error loading state file \"" + m.getFileName() + "\": " + e.getMessage());
System.exit(2); System.exit(2);
} }
} }
@ -70,29 +70,29 @@ public class Main {
try { try {
m.register(ns.getBoolean("voice")); m.register(ns.getBoolean("voice"));
} catch (IOException e) { } catch (IOException e) {
System.out.println("Request verify error: " + e.getMessage()); System.err.println("Request verify error: " + e.getMessage());
System.exit(3); System.exit(3);
} }
break; break;
case "verify": case "verify":
if (!m.userHasKeys()) { if (!m.userHasKeys()) {
System.out.println("User has no keys, first call register."); System.err.println("User has no keys, first call register.");
System.exit(1); System.exit(1);
} }
if (m.isRegistered()) { if (m.isRegistered()) {
System.out.println("User registration is already verified"); System.err.println("User registration is already verified");
System.exit(1); System.exit(1);
} }
try { try {
m.verifyAccount(ns.getString("verificationCode")); m.verifyAccount(ns.getString("verificationCode"));
} catch (IOException e) { } catch (IOException e) {
System.out.println("Verify error: " + e.getMessage()); System.err.println("Verify error: " + e.getMessage());
System.exit(3); System.exit(3);
} }
break; break;
case "send": case "send":
if (!m.isRegistered()) { if (!m.isRegistered()) {
System.out.println("User is not registered."); System.err.println("User is not registered.");
System.exit(1); System.exit(1);
} }
String messageText = ns.getString("message"); String messageText = ns.getString("message");
@ -100,7 +100,7 @@ public class Main {
try { try {
messageText = IOUtils.toString(System.in); messageText = IOUtils.toString(System.in);
} catch (IOException e) { } catch (IOException e) {
System.out.println("Failed to read message from stdin: " + e.getMessage()); System.err.println("Failed to read message from stdin: " + e.getMessage());
System.exit(1); System.exit(1);
} }
} }
@ -117,8 +117,8 @@ public class Main {
String mime = Files.probeContentType(Paths.get(attachment)); String mime = Files.probeContentType(Paths.get(attachment));
textSecureAttachments.add(new TextSecureAttachmentStream(attachmentStream, mime, attachmentSize, null)); textSecureAttachments.add(new TextSecureAttachmentStream(attachmentStream, mime, attachmentSize, null));
} catch (IOException e) { } catch (IOException e) {
System.out.println("Failed to add attachment \"" + attachment + "\": " + e.getMessage()); System.err.println("Failed to add attachment \"" + attachment + "\": " + e.getMessage());
System.out.println("Aborting sending."); System.err.println("Aborting sending.");
System.exit(1); System.exit(1);
} }
} }
@ -129,8 +129,8 @@ public class Main {
try { try {
recipients.add(m.getPushAddress(recipient)); recipients.add(m.getPushAddress(recipient));
} catch (InvalidNumberException e) { } catch (InvalidNumberException e) {
System.out.println("Failed to add recipient \"" + recipient + "\": " + e.getMessage()); System.err.println("Failed to add recipient \"" + recipient + "\": " + e.getMessage());
System.out.println("Aborting sending."); System.err.println("Aborting sending.");
System.exit(1); System.exit(1);
} }
} }
@ -138,18 +138,18 @@ public class Main {
break; break;
case "receive": case "receive":
if (!m.isRegistered()) { if (!m.isRegistered()) {
System.out.println("User is not registered."); System.err.println("User is not registered.");
System.exit(1); System.exit(1);
} }
try { try {
m.receiveMessages(5, true, new ReceiveMessageHandler(m)); m.receiveMessages(5, true, new ReceiveMessageHandler(m));
} catch (IOException e) { } catch (IOException e) {
System.out.println("Error while receiving message: " + e.getMessage()); System.err.println("Error while receiving message: " + e.getMessage());
System.exit(3); System.exit(3);
} catch (AssertionError e) { } catch (AssertionError e) {
System.out.println("Failed to receive message (Assertion): " + e.getMessage()); System.err.println("Failed to receive message (Assertion): " + e.getMessage());
System.out.println(e.getStackTrace()); System.err.println(e.getStackTrace());
System.out.println("If you use an Oracle JRE please check if you have unlimited strength crypto enabled, see README"); System.err.println("If you use an Oracle JRE please check if you have unlimited strength crypto enabled, see README");
System.exit(1); System.exit(1);
} }
break; break;
@ -211,22 +211,22 @@ public class Main {
try { try {
m.sendMessage(recipients, message); m.sendMessage(recipients, message);
} catch (IOException e) { } catch (IOException e) {
System.out.println("Failed to send message: " + e.getMessage()); System.err.println("Failed to send message: " + e.getMessage());
} catch (EncapsulatedExceptions e) { } catch (EncapsulatedExceptions e) {
System.out.println("Failed to send (some) messages:"); System.err.println("Failed to send (some) messages:");
for (NetworkFailureException n : e.getNetworkExceptions()) { for (NetworkFailureException n : e.getNetworkExceptions()) {
System.out.println("Network failure for \"" + n.getE164number() + "\": " + n.getMessage()); System.err.println("Network failure for \"" + n.getE164number() + "\": " + n.getMessage());
} }
for (UnregisteredUserException n : e.getUnregisteredUserExceptions()) { for (UnregisteredUserException n : e.getUnregisteredUserExceptions()) {
System.out.println("Unregistered user \"" + n.getE164Number() + "\": " + n.getMessage()); System.err.println("Unregistered user \"" + n.getE164Number() + "\": " + n.getMessage());
} }
for (UntrustedIdentityException n : e.getUntrustedIdentityExceptions()) { for (UntrustedIdentityException n : e.getUntrustedIdentityExceptions()) {
System.out.println("Untrusted Identity for \"" + n.getE164Number() + "\": " + n.getMessage()); System.err.println("Untrusted Identity for \"" + n.getE164Number() + "\": " + n.getMessage());
} }
} catch (AssertionError e) { } catch (AssertionError e) {
System.out.println("Failed to send message (Assertion): " + e.getMessage()); System.err.println("Failed to send message (Assertion): " + e.getMessage());
System.out.println(e.getStackTrace()); System.err.println(e.getStackTrace());
System.out.println("If you use an Oracle JRE please check if you have unlimited strength crypto enabled, see README"); System.err.println("If you use an Oracle JRE please check if you have unlimited strength crypto enabled, see README");
System.exit(1); System.exit(1);
} }
} }

View file

@ -122,7 +122,7 @@ class Manager {
writer.flush(); writer.flush();
writer.close(); writer.close();
} catch (Exception e) { } catch (Exception e) {
System.out.println("Saving file error: " + e.getMessage()); System.err.println("Saving file error: " + e.getMessage());
} }
} }
@ -259,7 +259,7 @@ class Manager {
if (returnOnTimeout) if (returnOnTimeout)
return; return;
} catch (InvalidVersionException e) { } catch (InvalidVersionException e) {
System.out.println("Ignoring error: " + e.getMessage()); System.err.println("Ignoring error: " + e.getMessage());
} }
save(); save();
} }