Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

Log Exceptions #230

Merged
merged 3 commits into from
Jun 30, 2017
Merged

Log Exceptions #230

merged 3 commits into from
Jun 30, 2017

Conversation

sarahsnow1
Copy link
Contributor

Overview

This is the first step towards improving and standardizing exception handling in Lost. Currently we catch and re-throw RuntimeExceptions thrown when interacting with the service, a hard stance for a library to take. To work towards giving developers the chance to handle recovering from these cases, this PR updates Lost to silently ignore RemoteExceptions. Future work will provide complete APIs to allow developers to handle recovering from these states as they see fit. It will potentially migrate existing silent failures to use these new APIs.

Closes #218, #223

} catch (RemoteException e) {
throw new RuntimeException(e);
Log.e(TAG, "Error occurred trying to get last Location " + e.getStackTrace());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also Log.e(TAG,message,throwable), wouldn't this be preferrable? Or has that method any downsides I am not aware of?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

throw new RuntimeException(e);
Log.e(TAG, "Error occurred trying to get LocationAvailability " + e.getStackTrace());
} finally {
return availability;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will return null on error. Assuming this how Google's APIs behave as well, it would be good to mention this in the javadoc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, updated

throw new RuntimeException(e);
Log.e(TAG, "Error occurred trying to get last Location " + e.getStackTrace());
} finally {
return location;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @westnordost pointed out below with availability, this will also return null if an error is encountered.

This behavior is consistent will play services.

throw new RuntimeException(e);
Log.e(TAG, "Error occurred trying to get last Location", e);
} finally {
return location;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just add a note in the Javadoc for getLastLocation() that null is also a valid return value here and this looks good to go.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do have this documented already If a location is not available, which should happen very rarely, null will be returned.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@sarahsnow1 sarahsnow1 merged commit 3ed32b3 into master Jun 30, 2017
@sarahsnow1 sarahsnow1 deleted the 218-dead-object-exception branch June 30, 2017 13:51
GulajavaMinistudio added a commit to GulajavaMinistudio/lost that referenced this pull request Jul 1, 2017
Copy link

@tallytalwar tallytalwar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too late to the party. But looks great. 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants