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 {
qrBitmap = qrCodeEncoder.encodeAsBitmap();
} catch (WriterException e) {
Log.e(TAG, e.getMessage());
Log.e(TAG, "Could not encode QR as bitmap", e);
}
return null;
}

View File

@ -376,8 +376,7 @@ public class UpdateService extends IntentService implements ProgressListener {
} catch (RepoUpdater.UpdateException e) {
errorRepos.add(repo.address);
repoErrors.add(e.getMessage());
Log.e(TAG, "Error updating repository " + repo.address + ": " + e.getMessage());
Log.e(TAG, Log.getStackTraceString(e));
Log.e(TAG, "Error updating repository " + repo.address, e);
}
}
@ -438,9 +437,7 @@ public class UpdateService extends IntentService implements ProgressListener {
}
}
} catch (Exception e) {
Log.e(TAG,
"Exception during update processing:\n"
+ Log.getStackTraceString(e));
Log.e(TAG, "Exception during update processing", e);
sendStatus(STATUS_ERROR_GLOBAL, e.getMessage());
}
}
@ -597,7 +594,7 @@ public class UpdateService extends IntentService implements ProgressListener {
try {
executeBatchWithStatus(AppProvider.getAuthority(), operations, currentCount, totalUpdateCount);
} 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 {
executeBatchWithStatus(ApkProvider.getAuthority(), operations, currentCount, totalApksAppsCount);
} 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();
return true;
} catch (IOException e) {
e.printStackTrace();
Log.e(TAG, "I/O error when copying a file", e);
return false;
}
}
@ -247,7 +247,7 @@ public final class Utils {
eventType = xml.nextToken();
}
} catch (PackageManager.NameNotFoundException | IOException | XmlPullParserException e) {
e.printStackTrace();
Log.e(TAG, "Could not get min/max sdk version", e);
}
return 0;
}
@ -364,8 +364,7 @@ public final class Utils {
ret = formatter.toString();
formatter.close();
} catch (Exception e) {
Log.w(TAG, "Unable to get certificate fingerprint.\n"
+ Log.getStackTraceString(e));
Log.w(TAG, "Unable to get certificate fingerprint", e);
}
return ret;
}

View File

@ -76,7 +76,7 @@ public class FileCompat extends Compatibility {
} catch (Exception e) {
// 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.
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.setTransactionSuccessful();
} catch (Exception e) {
Log.e(TAG, "Error renaming id to _id: " + e.getMessage());
Log.e(TAG, "Error renaming id to _id", e);
}
db.endTransaction();
}

View File

@ -103,7 +103,7 @@ public class InstalledAppProvider extends FDroidProvider {
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} 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
}

View File

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

View File

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

View File

@ -228,8 +228,7 @@ public class LocalRepoService extends Service {
Log.w(TAG, "port " + prev + " occupied, trying on " + FDroidApp.port + "!");
startService(new Intent(LocalRepoService.this, WifiStateChangeService.class));
} catch (IOException e) {
Log.e(TAG, "Could not start local repo HTTP server: " + e);
Log.e(TAG, Log.getStackTraceString(e));
Log.e(TAG, "Could not start local repo HTTP server", e);
}
Looper.loop(); // start the message receiving loop
}
@ -282,8 +281,7 @@ public class LocalRepoService extends Service {
jmdns = JmDNS.create();
jmdns.registerService(pairService);
} catch (IOException e) {
Log.e(TAG, "Error while registering jmdns service: " + e);
Log.e(TAG, Log.getStackTraceString(e));
Log.e(TAG, "Error while registering jmdns service", e);
}
}
}).start();

View File

@ -95,7 +95,7 @@ public class AsyncDownloadWrapper extends Handler {
} catch (InterruptedException e) {
sendMessage(MSG_DOWNLOAD_CANCELLED);
} 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);
data.putString(MSG_DATA, e.getLocalizedMessage());
Message message = new Message();

View File

@ -91,7 +91,7 @@ public class LocalHTTPD extends NanoHTTPD {
try {
session.parseBody(new HashMap<String, String>());
} 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.");
} catch (ResponseException re) {
return new Response(re.getStatus(), MIME_PLAINTEXT, re.getMessage());
@ -153,8 +153,7 @@ public class LocalHTTPD extends NanoHTTPD {
localRepoKeyStore.getKeyManagers());
makeSecure(factory);
} catch (LocalRepoKeyStore.InitException | IOException e) {
Log.e(TAG, "Could not enable HTTPS: " + e.getMessage());
Log.e(TAG, Log.getStackTraceString(e));
Log.e(TAG, "Could not enable HTTPS", e);
}
}

View File

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

View File

@ -533,7 +533,7 @@ public class ManageReposActivity extends ActionBarActivity {
return addressWithoutIndex;
}
} 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;
}

View File

@ -198,7 +198,7 @@ public class ConnectSwapActivity extends ActionBarActivity {
client.execute(host, request);
} catch (IOException e) {
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 {
client.close();
}