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 nested error handling #942

Merged
merged 1 commit into from
May 2, 2024
Merged

Improve nested error handling #942

merged 1 commit into from
May 2, 2024

Conversation

dangeross
Copy link
Collaborator

@dangeross dangeross commented Apr 22, 2024

This PR aims to remove wrapping of error strings rendered from nested errors within the SDK. The result being only outwardly facing errors prefix their variant name to the error string

Example 1:

Generic: Failed to create invoice: Invalid amount: Receive amount must be more than 0
Invalid amount: Receive amount must be more than 0

Example 2:

Generic: Generic: status: Unknown, message: "transport error", details: [], metadata: MetadataMap { headers: {} })
Service connectivity: status: Unknown, message: "transport error", details: [], metadata: MetadataMap { headers: {} })

Inspired by #885, but may not solve the Flutter issue

Copy link
Contributor

@erdemyerebasmaz erdemyerebasmaz left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

Copy link
Contributor

@ok300 ok300 left a comment

Choose a reason for hiding this comment

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

Good idea! Simple and elegant solution.

Just one NIT, otherwise LGTM.

@@ -396,7 +371,7 @@ impl From<SwapError> for ReceiveOnchainError {
impl From<PersistError> for ReceiveOnchainError {
fn from(err: PersistError) -> Self {
Self::Generic {
err: format!("Error when accessing local DB: {err}"),
err: err.to_string(),
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO the previous prefix was useful here, to help us pin-point this to a persister issue.

Copy link
Collaborator Author

@dangeross dangeross Apr 25, 2024

Choose a reason for hiding this comment

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

So the error previously would be:
Generic: Sql: Error when accessing local DB: <rusqlite::Error>
would this be better for SQL errors?
Generic: Error when accessing local DB: <rusqlite::Error>

I would apply this to the enum so all outward facing errors get the same

pub enum PersistError {
    ...

    #[error("Error when accessing local DB: {0}")]
    Sql(String),
}

Copy link
Contributor

Choose a reason for hiding this comment

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

The top one is best:
Generic: Sql: Error when accessing local DB: <rusqlite::Error>

I was only pointing out that the Error when accessing local DB prefix seemed to be removed, as I found it nowhere else in the code.

Copy link
Member

@roeierez roeierez left a comment

Choose a reason for hiding this comment

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

LGTM

@dangeross dangeross merged commit a486c24 into main May 2, 2024
7 checks passed
@dangeross dangeross deleted the savage-fix-nested-errors branch May 2, 2024 15:22
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.

4 participants