Exception logging improvements

* On error logs, always print the stack trace
* Log full stack traces instead of just exception names or messages
* Never use printStackTrace
This commit is contained in:
Daniel Martí 2015-09-11 17:41:24 -07:00
parent c0a13ad65f
commit de44771755
9 changed files with 12 additions and 14 deletions

View File

@ -530,7 +530,7 @@ public final class Utils {
return toHexString(mdbytes); return toHexString(mdbytes);
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Error reading \"" + apk.getAbsolutePath() Log.e(TAG, "Error reading \"" + apk.getAbsolutePath()
+ "\" to compute " + algo + " hash."); + "\" to compute " + algo + " hash.", e);
return null; return null;
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
Log.e(TAG, "Device does not support " + algo + " MessageDisgest algorithm"); Log.e(TAG, "Device does not support " + algo + " MessageDisgest algorithm");

View File

@ -214,7 +214,7 @@ public class SwapService extends Service {
client.execute(host, request); client.execute(host, request);
} catch (IOException e) { } catch (IOException e) {
notifyOfErrorOnUiThread(); notifyOfErrorOnUiThread();
Log.e(TAG, "Error while asking server to swap with us: " + e.getMessage()); Log.e(TAG, "Error while asking server to swap with us", e);
} finally { } finally {
client.close(); client.close();
} }

View File

@ -58,7 +58,7 @@ public class BonjourFinder extends PeerFinder<BonjourPeer> implements ServiceLis
Log.d(TAG, "Searching for Bonjour (mDNS) clients..."); Log.d(TAG, "Searching for Bonjour (mDNS) clients...");
jmdns = JmDNS.create(InetAddress.getByName(FDroidApp.ipAddressString)); jmdns = JmDNS.create(InetAddress.getByName(FDroidApp.ipAddressString));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Log.e(TAG, "", e);
} }
return null; return null;
} }

View File

@ -63,8 +63,7 @@ public class BonjourBroadcast extends SwapType {
setConnected(true); setConnected(true);
Log.d(TAG, "... Bounjour service started."); Log.d(TAG, "... Bounjour service started.");
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Error while registering jmdns service: " + e); Log.e(TAG, "Error while registering jmdns service", e);
Log.e(TAG, Log.getStackTraceString(e));
setConnected(false); setConnected(false);
} }
} }

View File

@ -79,8 +79,7 @@ public class WifiSwap extends SwapType {
context.startService(new Intent(context, WifiStateChangeService.class)); context.startService(new Intent(context, WifiStateChangeService.class));
} catch (IOException e) { } catch (IOException e) {
setConnected(false); setConnected(false);
Log.e(TAG, "Could not start local repo HTTP server: " + e); Log.e(TAG, "Could not start local repo HTTP server", e);
Log.e(TAG, Log.getStackTraceString(e));
} }
Looper.loop(); // start the message receiving loop Looper.loop(); // start the message receiving loop
} }

View File

@ -62,7 +62,7 @@ public class BluetoothDownloader extends Downloader {
try { try {
fileDetails = Request.createHEAD(sourceUrl.getPath(), connection).send().toFileDetails(); fileDetails = Request.createHEAD(sourceUrl.getPath(), connection).send().toFileDetails();
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Error getting file details from Bluetooth \"server\": " + e.getMessage()); Log.e(TAG, "Error getting file details from Bluetooth \"server\"", e);
} }
} }
return fileDetails; return fileDetails;

View File

@ -68,7 +68,7 @@ public class BluetoothServer extends Thread {
try { try {
serverSocket = adapter.listenUsingInsecureRfcommWithServiceRecord("FDroid App Swap", BluetoothConstants.fdroidUuid()); serverSocket = adapter.listenUsingInsecureRfcommWithServiceRecord("FDroid App Swap", BluetoothConstants.fdroidUuid());
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Error starting Bluetooth server socket, will stop the server now: " + e.getMessage()); Log.e(TAG, "Error starting Bluetooth server socket, will stop the server now", e);
swap.stop(); swap.stop();
isRunning = false; isRunning = false;
return; return;
@ -92,7 +92,7 @@ public class BluetoothServer extends Thread {
clients.add(client); clients.add(client);
} }
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Error receiving client connection over Bluetooth server socket, will continue listening for other clients: " + e.getMessage()); Log.e(TAG, "Error receiving client connection over Bluetooth server socket, will continue listening for other clients", e);
} }
} }
isRunning = false; isRunning = false;
@ -118,7 +118,7 @@ public class BluetoothServer extends Thread {
connection = new BluetoothConnection(socket); connection = new BluetoothConnection(socket);
connection.open(); connection.open();
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Error listening for incoming connections over bluetooth - " + e.getMessage()); Log.e(TAG, "Error listening for incoming connections over bluetooth", e);
return; return;
} }
@ -129,7 +129,7 @@ public class BluetoothServer extends Thread {
Request incomingRequest = Request.listenForRequest(connection); Request incomingRequest = Request.listenForRequest(connection);
handleRequest(incomingRequest).send(connection); handleRequest(incomingRequest).send(connection);
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Error receiving incoming connection over bluetooth - " + e.getMessage()); Log.e(TAG, "Error receiving incoming connection over bluetooth", e);
break; break;
} }

View File

@ -51,7 +51,7 @@ public class Response {
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
// Not quite sure what to do in the case of a phone not supporting UTF-8, so lets // Not quite sure what to do in the case of a phone not supporting UTF-8, so lets
// throw a runtime exception and hope that we get good bug reports if this ever happens. // throw a runtime exception and hope that we get good bug reports if this ever happens.
Log.e(TAG, "Device does not support UTF-8: " + e.getMessage()); Log.e(TAG, "Device does not support UTF-8", e);
throw new IllegalStateException("Device does not support UTF-8.", e); throw new IllegalStateException("Device does not support UTF-8.", e);
} }
} }

View File

@ -715,7 +715,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
broadcast(TYPE_COMPLETE); broadcast(TYPE_COMPLETE);
} catch (Exception e) { } catch (Exception e) {
broadcast(TYPE_ERROR); broadcast(TYPE_ERROR);
e.printStackTrace(); Log.e(TAG, "", e);
} }
return null; return null;
} }