gofr icon indicating copy to clipboard operation
gofr copied to clipboard

Refactor and improve error struct

Open srijan-27 opened this issue 6 months ago • 0 comments

          Now, the code is clearer to me. Thanks for the changes by the way.

I would like to suggest something that would make more sense according to me

Here the code relies (and already relied) on something that single purpose could be defined by these:

  • we need to be able to catch this error
  • we want to provide a meaningful error message that will contain the kind.

The current way is OK, but somehow overkill

Here is what I would code if I had to.

We don't define a struct, we define a simple sentinel error. This will ensure we can catch the error with a simple errors.Is

var ErrUnexpectedPointer = errors.New("unexpected pointer")

Then we use fmt.Errorf("%w to %s", ErrUnexpectedPointer, rv.Kind.String()) here

I know code was there, I know I'm asking to change something you are not responsible for. But, I report what I would have expected here.

As the errors are now exported, I would expect them to be clean.

Please let me know what you think about it

Originally posted by @ccoVeille in https://github.com/gofr-dev/gofr/pull/860#discussion_r1699988723

srijan-27 avatar Aug 05 '24 08:08 srijan-27