Skip to content

[Enhancement]: Implement Robust Error Handling in DataStoreManager #18

@theMr17

Description

@theMr17

Summary of Improvement

The current implementation of the DataStoreManager lacks consistent error handling and a clear categorization of errors. This update aims to improve the error-handling strategy by introducing a runDataStoreCatching function that wraps DataStore operations with specific error handling, ensuring more predictable and meaningful results when dealing with errors. Additionally, it includes a utility function to convert error types into user-friendly messages.

Current Implementation

  • The getAccessToken() and setAccessToken() methods in DataStoreManager currently do not consistently handle errors.
  • Error handling is done using basic try-catch, which lacks categorization or distinction between different error types (e.g., I/O issues, serialization problems).
  • There is no mechanism in place for converting these errors into user-friendly messages that can be shown to the user.

Proposed Solution

  1. Introduce runDataStoreCatching:

    • This function will wrap DataStore operations, allowing errors to be categorized into PersistenceError types (IO, SERIALIZATION, UNKNOWN).
    • It will return a Result type, which encapsulates both successful outcomes (Result.Success) and error states (Result.Error).
  2. Enhance getAccessToken() and setAccessToken():

    • These methods will be refactored to use runDataStoreCatching, returning a Result object.
    • This will help distinguish between successful token retrieval and potential issues like I/O or serialization errors.
  3. Add PersistenceError Enum:

    • Create a new PersistenceError enum that categorizes errors that may occur during persistence operations, such as IO, SERIALIZATION, and UNKNOWN.
  4. Create Utility Function for Error Translation:

    • A new function PersistenceError.toString() will be added to convert these errors into localized user-friendly strings, which will be displayed in the UI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovements or additions to existing feature/code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions