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: suggestion how to improve spverrors #749

Closed
wants to merge 5 commits into from

Conversation

chris-4chain
Copy link
Contributor

AI generated summary

This pull request introduces significant changes to the error handling mechanism across multiple files in the codebase. The primary focus is on replacing the existing error wrapping approach with a new custom error type, spverrors.Error, and updating related functions to use this new type.

Error Handling Improvements:

Utility and Test Updates:

  • Utility Functions:

    • engine/spverrors/utils.go: Updated Wrapf and Newf functions to utilize the new spverrors.Error type and added a new Of function to create spverrors.Error from existing errors.
  • Test Adjustments:

These changes collectively enhance the robustness and consistency of error handling throughout the codebase.

Pull Request Checklist

  • 📖 I created my PR using provided : CODE_STANDARDS
  • 📖 I have read the short Code of Conduct: CODE_OF_CONDUCT
  • 🏠 I tested my changes locally.
  • ✅ I have provided tests for my changes.
  • 📝 I have used conventional commits.
  • 📗 I have updated any related documentation.
  • 💾 PR was issued based on the Github or Jira issue.

Copy link

Manual Tests

ℹ️ Remember to ask team members to perform manual tests and to assign tested label after testing.

@@ -0,0 +1,157 @@
package spverrors
Copy link
Contributor

@dzolt-4chain dzolt-4chain Oct 21, 2024

Choose a reason for hiding this comment

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

With these changes now, shouldn't SPVError in models be removed? I dont see them being used anywhere now

Copy link
Contributor Author

@chris-4chain chris-4chain Oct 21, 2024

Choose a reason for hiding this comment

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

Maybe, but I wanted to present the key concept for now.
If you liked it, I would try to adjust the whole codebase to it.

... Also removing SPVError.

}
return errors.Wrap(err, format+" caused by")
return NewErrorf(format, args...).Wrap(err)
}

// Newf creates a new error with a message (which can be formatted)
func Newf(message string, args ...interface{}) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

If this and the above method are calling exported methods and doesn't do anything else, wouldn't it be better to isntead of using Wrapf to use NewErrorf everywhere? I understand this was made to make less changes in existing code, but what do you think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would be better - and I will change it - but after we agree that we want to go for it 😄

@@ -89,7 +89,7 @@ func (c *TaskManager) loadTaskQ(ctx context.Context) error {
c.options.taskq.queue = q
if factoryType == FactoryRedis {
if err := q.Consumer().Start(ctx); err != nil {
return spverrors.Wrapf(err, "failed to start consuming tasks from redis: %v")
return spverrors.Wrapf(err, "failed to start consuming tasks from redis")
Copy link
Contributor

@dzolt-4chain dzolt-4chain Oct 21, 2024

Choose a reason for hiding this comment

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

If no arguments are here I think it should be NewError("failed to start consuming tasks from redis").Wrap(err) but it's a minor, you can leave it as it is, just a nick pick

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Will update in "actual" PR 👍

PublicMessage string
HTTPStatus int

code string
Copy link
Contributor

Choose a reason for hiding this comment

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

Also any particular reason to make these fields private?

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.

2 participants