Properly log exceptions

This commit is contained in:
Daniel Martí 2015-08-20 19:21:50 -07:00
parent ce8c928337
commit 8669fddd70
14 changed files with 31 additions and 48 deletions

View File

@ -59,7 +59,7 @@ public class QrGenAsyncTask extends AsyncTask<String, Void, Void> {
try { try {
qrBitmap = qrCodeEncoder.encodeAsBitmap(); qrBitmap = qrCodeEncoder.encodeAsBitmap();
} catch (WriterException e) { } catch (WriterException e) {
Log.e(TAG, e.getMessage()); Log.e(TAG, "Could not encode QR as bitmap", e);
} }
return null; return null;
} }

View File

@ -376,8 +376,7 @@ public class UpdateService extends IntentService implements ProgressListener {
} catch (RepoUpdater.UpdateException e) { } catch (RepoUpdater.UpdateException e) {
errorRepos.add(repo.address); errorRepos.add(repo.address);
repoErrors.add(e.getMessage()); repoErrors.add(e.getMessage());
Log.e(TAG, "Error updating repository " + repo.address + ": " + e.getMessage()); Log.e(TAG, "Error updating repository " + repo.address, e);
Log.e(TAG, Log.getStackTraceString(e));
} }
} }
@ -438,9 +437,7 @@ public class UpdateService extends IntentService implements ProgressListener {
} }
} }
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, Log.e(TAG, "Exception during update processing", e);
"Exception during update processing:\n"
+ Log.getStackTraceString(e));
sendStatus(STATUS_ERROR_GLOBAL, e.getMessage()); sendStatus(STATUS_ERROR_GLOBAL, e.getMessage());
} }
} }
@ -597,7 +594,7 @@ public class UpdateService extends IntentService implements ProgressListener {
try { try {
executeBatchWithStatus(AppProvider.getAuthority(), operations, currentCount, totalUpdateCount); executeBatchWithStatus(AppProvider.getAuthority(), operations, currentCount, totalUpdateCount);
} catch (RemoteException | OperationApplicationException e) { } catch (RemoteException | OperationApplicationException e) {
Log.e(TAG, e.getMessage()); Log.e(TAG, "Could not update or insert apps", e);
} }
} }
@ -656,7 +653,7 @@ public class UpdateService extends IntentService implements ProgressListener {
try { try {
executeBatchWithStatus(ApkProvider.getAuthority(), operations, currentCount, totalApksAppsCount); executeBatchWithStatus(ApkProvider.getAuthority(), operations, currentCount, totalApksAppsCount);
} catch (RemoteException | OperationApplicationException e) { } catch (RemoteException | OperationApplicationException e) {
Log.e(TAG, e.getMessage()); Log.e(TAG, "Could not update/insert apps", e);
} }
} }

View File

@ -165,7 +165,7 @@ public final class Utils {
input.close(); input.close();
return true; return true;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Log.e(TAG, "I/O error when copying a file", e);
return false; return false;
} }
} }
@ -247,7 +247,7 @@ public final class Utils {
eventType = xml.nextToken(); eventType = xml.nextToken();
} }
} catch (PackageManager.NameNotFoundException | IOException | XmlPullParserException e) { } catch (PackageManager.NameNotFoundException | IOException | XmlPullParserException e) {
e.printStackTrace(); Log.e(TAG, "Could not get min/max sdk version", e);
} }
return 0; return 0;
} }
@ -364,8 +364,7 @@ public final class Utils {
ret = formatter.toString(); ret = formatter.toString();
formatter.close(); formatter.close();
} catch (Exception e) { } catch (Exception e) {
Log.w(TAG, "Unable to get certificate fingerprint.\n" Log.w(TAG, "Unable to get certificate fingerprint", e);
+ Log.getStackTraceString(e));
} }
return ret; return ret;
} }

View File

@ -76,7 +76,7 @@ public class FileCompat extends Compatibility {
} catch (Exception e) { } catch (Exception e) {
// Should catch more specific exceptions than just "Exception" here, but there are // Should catch more specific exceptions than just "Exception" here, but there are
// some which come from libcore.io.Libcore, which we don't have access to at compile time. // some which come from libcore.io.Libcore, which we don't have access to at compile time.
Log.e(TAG, "Could not symlink " + source.getAbsolutePath() + " to " + dest.getAbsolutePath() + ": " + e.getMessage()); Log.e(TAG, "Could not symlink " + source.getAbsolutePath() + " to " + dest.getAbsolutePath(), e);
} }
} }

View File

@ -181,7 +181,7 @@ public class DBHelper extends SQLiteOpenHelper {
db.execSQL("DROP TABLE " + tempTableName + ";"); db.execSQL("DROP TABLE " + tempTableName + ";");
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Error renaming id to _id: " + e.getMessage()); Log.e(TAG, "Error renaming id to _id", e);
} }
db.endTransaction(); db.endTransaction();
} }

View File

@ -103,7 +103,7 @@ public class InstalledAppProvider extends FDroidProvider {
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} catch (Resources.NotFoundException e) { } catch (Resources.NotFoundException e) {
Utils.DebugLog(TAG, "getApplicationLabel: " + e.getMessage()); Utils.DebugLog(TAG, "Could not get application label", e);
} }
return packageName; // all else fails, return id return packageName; // all else fails, return id
} }

View File

@ -156,12 +156,10 @@ public class LocalRepoKeyStore {
wrappedKeyManager wrappedKeyManager
}; };
} catch (UnrecoverableKeyException | KeyStoreException | NoSuchAlgorithmException | CertificateException | OperatorCreationException | IOException e) { } catch (UnrecoverableKeyException | KeyStoreException | NoSuchAlgorithmException | CertificateException | OperatorCreationException | IOException e) {
Log.e(TAG, "Error loading keystore: " + e.getMessage()); Log.e(TAG, "Error loading keystore", e);
Log.e(TAG, Log.getStackTraceString(e));
// TODO: Remove once we have a proper fix for #334 // TODO: Remove once we have a proper fix for #334
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Log.e(TAG, "Error loading keystore: " + e.getMessage()); Log.e(TAG, "Error loading keystore", e);
Log.e(TAG, Log.getStackTraceString(e));
Log.e(TAG, "See https://gitlab.com/fdroid/fdroidclient/issues/334"); Log.e(TAG, "See https://gitlab.com/fdroid/fdroidclient/issues/334");
} }
} }
@ -183,8 +181,7 @@ public class LocalRepoKeyStore {
FDroidApp.ipAddressString); FDroidApp.ipAddressString);
addToStore(HTTP_CERT_ALIAS, kerplappKeypair, indexCert); addToStore(HTTP_CERT_ALIAS, kerplappKeypair, indexCert);
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Failed to setup HTTPS certificate: " + e); Log.e(TAG, "Failed to setup HTTPS certificate", e);
Log.e(TAG, Log.getStackTraceString(e));
} }
} }
@ -213,8 +210,7 @@ public class LocalRepoKeyStore {
zipSigner.signZip(input.getAbsolutePath(), output.getAbsolutePath()); zipSigner.signZip(input.getAbsolutePath(), output.getAbsolutePath());
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException | GeneralSecurityException | IOException e) { } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | GeneralSecurityException | IOException e) {
Log.e(TAG, "Unable to sign local repo index: " + e); Log.e(TAG, "Unable to sign local repo index", e);
Log.e(TAG, Log.getStackTraceString(e));
} }
} }
@ -243,8 +239,7 @@ public class LocalRepoKeyStore {
if (key instanceof PrivateKey) if (key instanceof PrivateKey)
return keyStore.getCertificate(INDEX_CERT_ALIAS); return keyStore.getCertificate(INDEX_CERT_ALIAS);
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {
Log.e(TAG, "Unable to get certificate for local repo: " + e); Log.e(TAG, "Unable to get certificate for local repo", e);
Log.e(TAG, Log.getStackTraceString(e));
} }
return null; return null;
} }

View File

@ -136,7 +136,7 @@ public class LocalRepoManager {
if (Utils.symlinkOrCopyFile(apkFile, fdroidApkLink)) if (Utils.symlinkOrCopyFile(apkFile, fdroidApkLink))
fdroidClientURL = "/" + fdroidApkLink.getName(); fdroidClientURL = "/" + fdroidApkLink.getName();
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
e.printStackTrace(); Log.e(TAG, "Could not set up F-Droid apk in the webroot", e);
} }
return fdroidClientURL; return fdroidClientURL;
} }
@ -176,8 +176,7 @@ public class LocalRepoManager {
symlinkEntireWebRootElsewhere("../../", repoDirCaps); symlinkEntireWebRootElsewhere("../../", repoDirCaps);
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Error writing local repo index: " + e.getMessage()); Log.e(TAG, "Error writing local repo index", e);
Log.e(TAG, Log.getStackTraceString(e));
} }
} }
@ -256,8 +255,7 @@ public class LocalRepoManager {
PackageInfo packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_META_DATA); PackageInfo packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_META_DATA);
app.icon = getIconFile(packageName, packageInfo.versionCode).getName(); app.icon = getIconFile(packageName, packageInfo.versionCode).getName();
} catch (PackageManager.NameNotFoundException | CertificateEncodingException | IOException e) { } catch (PackageManager.NameNotFoundException | CertificateEncodingException | IOException e) {
Log.e(TAG, "Error adding app to local repo: " + e.getMessage()); Log.e(TAG, "Error adding app to local repo", e);
Log.e(TAG, Log.getStackTraceString(e));
return; return;
} }
Utils.DebugLog(TAG, "apps.put: " + packageName); Utils.DebugLog(TAG, "apps.put: " + packageName);
@ -276,7 +274,7 @@ public class LocalRepoManager {
appInfo = pm.getApplicationInfo(app.id, PackageManager.GET_META_DATA); appInfo = pm.getApplicationInfo(app.id, PackageManager.GET_META_DATA);
copyIconToRepo(appInfo.loadIcon(pm), app.id, app.installedApk.vercode); copyIconToRepo(appInfo.loadIcon(pm), app.id, app.installedApk.vercode);
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
e.printStackTrace(); Log.e(TAG, "Error getting app icon", e);
} }
} }
} }
@ -303,7 +301,7 @@ public class LocalRepoManager {
bitmap.compress(CompressFormat.PNG, 100, out); bitmap.compress(CompressFormat.PNG, 100, out);
out.close(); out.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); Log.e(TAG, "Error copying icon to repo", e);
} }
} }
@ -478,7 +476,7 @@ public class LocalRepoManager {
try { try {
new IndexXmlBuilder(context, apps).build(new FileWriter(xmlIndex)); new IndexXmlBuilder(context, apps).build(new FileWriter(xmlIndex));
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, Log.getStackTraceString(e)); Log.e(TAG, "Could not write index jar", e);
Toast.makeText(context, R.string.failed_to_create_index, Toast.LENGTH_LONG).show(); Toast.makeText(context, R.string.failed_to_create_index, Toast.LENGTH_LONG).show();
return; return;
} }

View File

@ -228,8 +228,7 @@ public class LocalRepoService extends Service {
Log.w(TAG, "port " + prev + " occupied, trying on " + FDroidApp.port + "!"); Log.w(TAG, "port " + prev + " occupied, trying on " + FDroidApp.port + "!");
startService(new Intent(LocalRepoService.this, WifiStateChangeService.class)); startService(new Intent(LocalRepoService.this, WifiStateChangeService.class));
} catch (IOException e) { } catch (IOException e) {
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
} }
@ -282,8 +281,7 @@ public class LocalRepoService extends Service {
jmdns = JmDNS.create(); jmdns = JmDNS.create();
jmdns.registerService(pairService); jmdns.registerService(pairService);
} 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));
} }
} }
}).start(); }).start();

View File

@ -95,7 +95,7 @@ public class AsyncDownloadWrapper extends Handler {
} catch (InterruptedException e) { } catch (InterruptedException e) {
sendMessage(MSG_DOWNLOAD_CANCELLED); sendMessage(MSG_DOWNLOAD_CANCELLED);
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, e.getMessage() + ": " + Log.getStackTraceString(e)); Log.e(TAG, "I/O exception in download thread", e);
Bundle data = new Bundle(1); Bundle data = new Bundle(1);
data.putString(MSG_DATA, e.getLocalizedMessage()); data.putString(MSG_DATA, e.getLocalizedMessage());
Message message = new Message(); Message message = new Message();

View File

@ -91,7 +91,7 @@ public class LocalHTTPD extends NanoHTTPD {
try { try {
session.parseBody(new HashMap<String, String>()); session.parseBody(new HashMap<String, String>());
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, e.getMessage()); Log.e(TAG, "An error occured while parsing the POST body", e);
return new Response(Response.Status.INTERNAL_ERROR, MIME_PLAINTEXT, "Internal server error, check logcat on server for details."); return new Response(Response.Status.INTERNAL_ERROR, MIME_PLAINTEXT, "Internal server error, check logcat on server for details.");
} catch (ResponseException re) { } catch (ResponseException re) {
return new Response(re.getStatus(), MIME_PLAINTEXT, re.getMessage()); return new Response(re.getStatus(), MIME_PLAINTEXT, re.getMessage());
@ -153,8 +153,7 @@ public class LocalHTTPD extends NanoHTTPD {
localRepoKeyStore.getKeyManagers()); localRepoKeyStore.getKeyManagers());
makeSecure(factory); makeSecure(factory);
} catch (LocalRepoKeyStore.InitException | IOException e) { } catch (LocalRepoKeyStore.InitException | IOException e) {
Log.e(TAG, "Could not enable HTTPS: " + e.getMessage()); Log.e(TAG, "Could not enable HTTPS", e);
Log.e(TAG, Log.getStackTraceString(e));
} }
} }

View File

@ -135,11 +135,8 @@ public class WifiStateChangeService extends Service {
if (Preferences.get().isLocalRepoHttpsEnabled()) if (Preferences.get().isLocalRepoHttpsEnabled())
localRepoKeyStore.setupHTTPSCertificate(); localRepoKeyStore.setupHTTPSCertificate();
} catch (LocalRepoKeyStore.InitException e) { } catch (LocalRepoKeyStore.InitException | InterruptedException e) {
Log.e(TAG, "Unable to configure a fingerprint or HTTPS for the local repo: " + e.getMessage()); Log.e(TAG, "Unable to configure a fingerprint or HTTPS for the local repo", e);
Log.e(TAG, Log.getStackTraceString(e));
} catch (InterruptedException e) {
Log.e(TAG, Log.getStackTraceString(e));
} }
return null; return null;
} }

View File

@ -533,7 +533,7 @@ public class ManageReposActivity extends ActionBarActivity {
return addressWithoutIndex; return addressWithoutIndex;
} }
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Error while searching for repo at " + addressWithoutIndex + ": " + e.getMessage()); Log.e(TAG, "Error while searching for repo at " + addressWithoutIndex, e);
return originalAddress; return originalAddress;
} }

View File

@ -198,7 +198,7 @@ public class ConnectSwapActivity extends ActionBarActivity {
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();
} }