Skip to content

Enforce handle_fatal_reject type safety#1058

Merged
arminsabouri merged 1 commit intopayjoin:masterfrom
arminsabouri:simplify-handle-fatal
Sep 11, 2025
Merged

Enforce handle_fatal_reject type safety#1058
arminsabouri merged 1 commit intopayjoin:masterfrom
arminsabouri:simplify-handle-fatal

Conversation

@arminsabouri
Copy link
Collaborator

handle_fatal_reject is a utility method intended to reduce boiler plate and duplicated code. Changing the method param to RejectFatal enforces better type safety and further reduces boiler plate.

Pull Request Checklist

Please confirm the following before requesting review:

`handle_fatal_reject` is a utility method intended to
reduce boiler plate and duplicated code. Changing the method param to
`RejectFatal` enforces better type safety and further reduces boiler
plate.
@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 17648295731

Details

  • 14 of 16 (87.5%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.02%) to 86.002%

Changes Missing Coverage Covered Lines Changed/Added Lines %
payjoin/src/core/persist.rs 14 16 87.5%
Totals Coverage Status
Change from base Build 17593913920: -0.02%
Covered Lines: 8233
Relevant Lines: 9573

💛 - Coveralls

@arminsabouri arminsabouri self-assigned this Sep 11, 2025
Copy link
Contributor

@DanGould DanGould left a comment

Choose a reason for hiding this comment

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

utACK

I think this is still not the right abstraction but no less wrong than what was there before

Comment on lines +513 to +526
) -> InternalPersistedError<Err, Self::InternalStorageError>
where
Err: std::error::Error,
{
self.save_event(event).map_err(InternalPersistedError::Storage)?;
let RejectFatal(event, error) = reject_fatal;
if let Err(e) = self.save_event(event) {
return InternalPersistedError::Storage(e);
}
// Session is in a terminal state, close it
self.close().map_err(InternalPersistedError::Storage)
if let Err(e) = self.close() {
return InternalPersistedError::Storage(e);
}

InternalPersistedError::Fatal(error)
Copy link
Contributor

Choose a reason for hiding this comment

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

InternalPersistedError type on

       if let Err(e) = self.close() {
            return InternalPersistedError::Storage(e);
        }

seems wrong to me because this error is never persisted. but no less wrong than what's here right now so the change is fine with me.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think something like

Result<InternalPersistedError, Self::InternalStorageError>

Is more like it. Success means you persisted an error. Failure means you have a persistence (Storage) error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Which error? InternalPersistedError::Storage(e); ? That is an application produced error. I.e the application is indicating that it cannot store an event(which in this case is error).

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case I don't think it makes sense to be part of the PersistedError variant (unless it's really a PersistenceError. Could just use ImplementationError

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This method and its caller can fail in either two ways. API error or a storage error. We can't just use ImplementationError. Perhaps your issue is more with the naming of PersistenceError?

Copy link
Collaborator

@spacebear21 spacebear21 left a comment

Choose a reason for hiding this comment

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

This refactor seems premature since the changes for #793 mean that:

  • handle_fatal_reject won't be responsible for closing sessions anymore
  • Transient errors will also need to be saved before they are returned, so maybe a shared handler would be less boilerplate

@arminsabouri
Copy link
Collaborator Author

This refactor seems premature since the changes for #793 mean that:

  • handle_fatal_reject won't be responsible for closing sessions anymore

Thats a good point. In #793 the suggestons is to close the session after the post the err_req?

  • Transient errors will also need to be saved before they are returned, so maybe a shared handler would be less boilerplate

Why would we save transient error? for auditability?

@spacebear21
Copy link
Collaborator

In #793 the suggestons is to close the session after the post the err_req?

yes

Why would we save transient error? for auditability?

Nevermind we wouldn't, I got those mixed up with non-repliable fatal errors

@spacebear21
Copy link
Collaborator

I'm not opposed to merging this anyway if the refactor helps in other PRs in the meantime fwiw

@arminsabouri arminsabouri merged commit 3487053 into payjoin:master Sep 11, 2025
10 checks passed
@arminsabouri arminsabouri deleted the simplify-handle-fatal branch September 11, 2025 18:52
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