Add Log.d for QueryFailedException

This commit is contained in:
Tim Bray 2014-05-22 16:56:28 -07:00
parent 8a2ffd8f90
commit dfd5aa65a5
7 changed files with 28 additions and 40 deletions

View File

@ -200,12 +200,12 @@ public class HkpKeyserver extends Keyserver {
} }
@Override @Override
public ArrayList<ImportKeysListEntry> search(String query) throws QueryException, TooManyResponses, public ArrayList<ImportKeysListEntry> search(String query) throws QueryException,
InsufficientQuery { QueryNeedsRepairException {
ArrayList<ImportKeysListEntry> results = new ArrayList<ImportKeysListEntry>(); ArrayList<ImportKeysListEntry> results = new ArrayList<ImportKeysListEntry>();
if (query.length() < 3) { if (query.length() < 3) {
throw new InsufficientQuery(); throw new QueryTooShortException();
} }
String encodedQuery; String encodedQuery;
@ -226,9 +226,9 @@ public class HkpKeyserver extends Keyserver {
if (e.getData().toLowerCase(Locale.US).contains("no keys found")) { if (e.getData().toLowerCase(Locale.US).contains("no keys found")) {
return results; return results;
} else if (e.getData().toLowerCase(Locale.US).contains("too many")) { } else if (e.getData().toLowerCase(Locale.US).contains("too many")) {
throw new TooManyResponses(); throw new TooManyResponsesException();
} else if (e.getData().toLowerCase(Locale.US).contains("insufficient")) { } else if (e.getData().toLowerCase(Locale.US).contains("insufficient")) {
throw new InsufficientQuery(); throw new QueryTooShortException();
} }
} }
throw new QueryException("querying server(s) for '" + mHost + "' failed"); throw new QueryException("querying server(s) for '" + mHost + "' failed");

View File

@ -34,8 +34,8 @@ public class KeybaseKeyserver extends Keyserver {
private String mQuery; private String mQuery;
@Override @Override
public ArrayList<ImportKeysListEntry> search(String query) throws QueryException, TooManyResponses, public ArrayList<ImportKeysListEntry> search(String query) throws QueryException,
InsufficientQuery { QueryNeedsRepairException {
ArrayList<ImportKeysListEntry> results = new ArrayList<ImportKeysListEntry>(); ArrayList<ImportKeysListEntry> results = new ArrayList<ImportKeysListEntry>();
if (query.startsWith("0x")) { if (query.startsWith("0x")) {
@ -84,6 +84,7 @@ public class KeybaseKeyserver extends Keyserver {
} }
private ImportKeysListEntry makeEntry(JSONObject match) throws QueryException, JSONException { private ImportKeysListEntry makeEntry(JSONObject match) throws QueryException, JSONException {
final ImportKeysListEntry entry = new ImportKeysListEntry(); final ImportKeysListEntry entry = new ImportKeysListEntry();
entry.setQuery(mQuery); entry.setQuery(mQuery);

View File

@ -32,20 +32,23 @@ public abstract class Keyserver {
} }
} }
public static class TooManyResponses extends Exception { public static class QueryNeedsRepairException extends Exception {
private static final long serialVersionUID = 2693768928624654512L;
}
public static class TooManyResponsesException extends QueryNeedsRepairException {
private static final long serialVersionUID = 2703768928624654513L; private static final long serialVersionUID = 2703768928624654513L;
} }
public static class InsufficientQuery extends Exception { public static class QueryTooShortException extends QueryNeedsRepairException {
private static final long serialVersionUID = 2703768928624654514L;
} }
public static class AddKeyException extends Exception { public static class AddKeyException extends Exception {
private static final long serialVersionUID = -507574859137295530L; private static final long serialVersionUID = -507574859137295530L;
} }
abstract List<ImportKeysListEntry> search(String query) throws QueryException, TooManyResponses, abstract List<ImportKeysListEntry> search(String query) throws QueryException,
InsufficientQuery; QueryNeedsRepairException;
abstract String get(String keyIdHex) throws QueryException; abstract String get(String keyIdHex) throws QueryException;

View File

@ -273,38 +273,28 @@ public class ImportKeysListFragment extends ListFragment implements
break; break;
case LOADER_ID_SERVER_QUERY: case LOADER_ID_SERVER_QUERY:
case LOADER_ID_KEYBASE:
// TODO: possibly fine-tune message building for these two cases
if (error == null) { if (error == null) {
AppMsg.makeText( AppMsg.makeText(
getActivity(), getResources().getQuantityString(R.plurals.keys_found, getActivity(), getResources().getQuantityString(R.plurals.keys_found,
mAdapter.getCount(), mAdapter.getCount()), mAdapter.getCount(), mAdapter.getCount()),
AppMsg.STYLE_INFO AppMsg.STYLE_INFO
).show(); ).show();
} else if (error instanceof Keyserver.InsufficientQuery) { } else if (error instanceof Keyserver.QueryTooShortException) {
AppMsg.makeText(getActivity(), R.string.error_keyserver_insufficient_query, AppMsg.makeText(getActivity(), R.string.error_keyserver_insufficient_query,
AppMsg.STYLE_ALERT).show(); AppMsg.STYLE_ALERT).show();
} else if (error instanceof Keyserver.QueryException) { } else if (error instanceof Keyserver.QueryException) {
AppMsg.makeText(getActivity(), R.string.error_keyserver_query, String alert = getActivity().getString(R.string.error_searching_keys);
AppMsg.STYLE_ALERT).show(); alert = alert + " (" + error.getLocalizedMessage() + ")";
} else if (error instanceof Keyserver.TooManyResponses) { AppMsg.makeText(getActivity(), alert, AppMsg.STYLE_ALERT).show();
} else if (error instanceof Keyserver.TooManyResponsesException) {
AppMsg.makeText(getActivity(), R.string.error_keyserver_too_many_responses, AppMsg.makeText(getActivity(), R.string.error_keyserver_too_many_responses,
AppMsg.STYLE_ALERT).show(); AppMsg.STYLE_ALERT).show();
} }
break; break;
case LOADER_ID_KEYBASE:
if (error == null) {
AppMsg.makeText(
getActivity(), getResources().getQuantityString(R.plurals.keys_found,
mAdapter.getCount(), mAdapter.getCount()),
AppMsg.STYLE_INFO
).show();
} else if (error instanceof Keyserver.QueryException) {
AppMsg.makeText(getActivity(), R.string.error_keyserver_query,
AppMsg.STYLE_ALERT).show();
}
default: default:
break; break;
} }

View File

@ -94,14 +94,10 @@ public class ImportKeysListKeybaseLoader
mEntryList.addAll(searchResult); mEntryList.addAll(searchResult);
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, null); mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, null);
} catch (Keyserver.InsufficientQuery e) {
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e);
} catch (Keyserver.QueryException e) { } catch (Keyserver.QueryException e) {
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e); mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e);
} catch (Keyserver.TooManyResponses e) { } catch (Keyserver.QueryNeedsRepairException e) {
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e); mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e);
} }
} }
} }

View File

@ -116,11 +116,9 @@ public class ImportKeysListServerLoader
mEntryList.addAll(searchResult); mEntryList.addAll(searchResult);
} }
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, null); mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, null);
} catch (Keyserver.InsufficientQuery e) {
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e);
} catch (Keyserver.QueryException e) { } catch (Keyserver.QueryException e) {
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e); mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e);
} catch (Keyserver.TooManyResponses e) { } catch (Keyserver.QueryNeedsRepairException e) {
mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e); mEntryListWrapper = new AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>(mEntryList, e);
} }
} }

View File

@ -295,9 +295,9 @@
<string name="error_jelly_bean_needed">You need Android 4.1 to use Android\'s NFC Beam feature!</string> <string name="error_jelly_bean_needed">You need Android 4.1 to use Android\'s NFC Beam feature!</string>
<string name="error_nfc_needed">NFC is not available on your device!</string> <string name="error_nfc_needed">NFC is not available on your device!</string>
<string name="error_nothing_import">Nothing to import!</string> <string name="error_nothing_import">Nothing to import!</string>
<string name="error_keyserver_insufficient_query">Insufficient server query</string> <string name="error_keyserver_insufficient_query">Key search query too short</string>
<string name="error_keyserver_query">Querying keyserver failed</string> <string name="error_searching_keys">Unrecoverable error searching for keys at server</string>
<string name="error_keyserver_too_many_responses">Too many possible keys. Please refine your query!</string> <string name="error_keyserver_too_many_responses">Key search query returned too many candidates; Please refine query</string>
<string name="error_import_file_no_content">File has no content</string> <string name="error_import_file_no_content">File has no content</string>
<string name="error_generic_report_bug">A generic error occurred, please create a new bug report for OpenKeychain.</string> <string name="error_generic_report_bug">A generic error occurred, please create a new bug report for OpenKeychain.</string>
<plurals name="error_import_non_pgp_part"> <plurals name="error_import_non_pgp_part">