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

improve error message #1

Merged
merged 1 commit into from
Sep 6, 2024
Merged

improve error message #1

merged 1 commit into from
Sep 6, 2024

Conversation

lijunchen
Copy link

@lijunchen lijunchen commented Sep 6, 2024

Copy link

  1. Removal of anyhow::anyhow in db.rs:

    • The line use anyhow::{anyhow, bail}; was changed to use anyhow::bail;. This removes the anyhow macro, which is used for constructing error messages. However, the function open still attempts to use anyhow! in its error handling logic. This discrepancy will lead to a compile-time error because anyhow! is no longer in scope.
    • Suggestion: Either reintroduce anyhow in the use statement or refactor the open function to not rely on anyhow!.
  2. Error Handling in db.rs:

    • The Reader::read and Writer::create functions have been changed to return custom error types (OpenError), but the error handling in read in load.rs still maps these errors to anyhow::Error. This might be unnecessary if the rest of the application is designed to handle OpenError.
    • Suggestion: Consider if mapping to anyhow::Error is still necessary or if you can propagate OpenError directly for consistency in error handling throughout the application.
  3. Error Display in OpenErrorKind:

    • In the OpenErrorKind enum, the fmt method for OpenErrorKind does not include the underlying error message. This might make the error less informative in some contexts.
    • Suggestion: Consider including the error message from the underlying error in the fmt method to provide more detailed output. For example:
      impl std::fmt::Display for OpenErrorKind {
          fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
              match self {
                  OpenErrorKind::OpenDB(err) => write!(f, "failed to open: {}", err),
                  OpenErrorKind::ReadDB(err) => write!(f, "failed to read: {}", err),
                  OpenErrorKind::CreateDB(err) => write!(f, "failed to create: {}", err),
              }
          }
      }

@lijunchen lijunchen merged commit 57092cd into main Sep 6, 2024
2 checks passed
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