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

feat: add safe effect helper #552

Merged
merged 6 commits into from
Sep 12, 2024
Merged

Conversation

alexruzenhack
Copy link
Contributor

@alexruzenhack alexruzenhack commented Sep 5, 2024

Acceptance Criteria

  • feat: add safeEffect as a saga helper
  • feat: wrap registerNanoContract effect on safeEffect

Issue: #550

Note

This PR can be cherry-picked to refactor/default-network branch.

Security Checklist

  • Make sure you do not include new dependencies in the project unless strictly necessary and do not include dev-dependencies as production ones. More dependencies increase the possibility of one of them being hijacked and affecting us.

*/
export function safeEffect(effect, onError) {
// eslint-disable-next-line func-names
return function* (payload) {
Copy link
Contributor

Choose a reason for hiding this comment

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

question(non-blocking): Why not name this function? Wouldn't it help in an eventual debugging session?

Copy link
Contributor Author

@alexruzenhack alexruzenhack Sep 10, 2024

Choose a reason for hiding this comment

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

I'm giving it a name _safeEffect: 611e63f. Thank you!

*/
function* registerNanoContractOnError(error) {
log.error('Unexpected error while registering Nano Contract.', error);
yield put(nanoContractRegisterFailure(failureMessage.blueprintInfoFailure));
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Why use the blueprintInfo failure when the error was on a registration event?

Copy link
Contributor Author

@alexruzenhack alexruzenhack Sep 10, 2024

Choose a reason for hiding this comment

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

Fixed: b405bbe

takeEvery(types.NANOCONTRACT_REGISTER_REQUEST, registerNanoContract),
takeEvery(
types.NANOCONTRACT_REGISTER_REQUEST,
safeEffect(registerNanoContract, registerNanoContractOnError)
Copy link
Contributor

Choose a reason for hiding this comment

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

⭐ Nice solution! For the future, I'm thinking of a way to make it more generic, and not require two handler functions for each effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be awesome!

@alexruzenhack alexruzenhack merged commit 57b782c into master Sep 12, 2024
1 check passed
@alexruzenhack alexruzenhack deleted the feat/add-safe-effect-utils branch September 12, 2024 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants