Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not hard-crash on missing usernames #448

Merged
merged 1 commit into from
Feb 29, 2024

Conversation

theospears
Copy link
Collaborator

Previously we were using username! to look up usernames. This would throw a fatal exception if the username was not available, crashing the app. In particular attempts to update HealthKit metrics could hit this after logging out from the app.

Avoid this by centralizing the username lookup logic in the request manager making URLs in the app slightly more readable, and have it throw a catchable exception. This could theoretically cause issues in the case that a URL contains an additional {username} string, but this seems unlikely.

Testing:
Launched the app on my phone and checked it could load goals.
Signed out and did not immediately experience a crash.

@theospears
Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @theospears and the rest of your teammates on Graphite Graphite

@@ -110,7 +110,7 @@ public class CurrentUserManager {
// Fetch a user from the persistent store
let request = NSFetchRequest<User>(entityName: "User")
// TODO: Handle (or at least log) an error here
let users = try? (context ?? container.viewContext).fetch(request)
let users = try? (context ?? container.newBackgroundContext()).fetch(request)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Drive by attempt to fix an unrelated crash

@theospears theospears merged commit b5a3e79 into master Feb 29, 2024
2 checks passed
@theospears theospears deleted the use-exception-for-username branch February 29, 2024 03:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant