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

Add errors helper package #1

Merged
merged 9 commits into from
Mar 10, 2025
Merged

Conversation

hossainemruz
Copy link
Member

This PR adds helper package for wrapping errors with additional context.

Signed-off-by: Emruz Hossain <[email protected]>
Signed-off-by: Emruz Hossain <[email protected]>
Signed-off-by: Emruz Hossain <[email protected]>
@hossainemruz hossainemruz changed the title Add error helper package Add errors helper package Mar 7, 2025
Signed-off-by: Emruz Hossain <[email protected]>
Signed-off-by: Emruz Hossain <[email protected]>
Signed-off-by: Emruz Hossain <[email protected]>
@hossainemruz hossainemruz requested a review from pedjak March 7, 2025 17:41
Signed-off-by: Emruz Hossain <[email protected]>
@hossainemruz hossainemruz requested a review from pedjak March 10, 2025 11:37
return w.err
}

type Metadata []string
Copy link

Choose a reason for hiding this comment

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

why not []any?

Copy link
Member Author

Choose a reason for hiding this comment

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

If we use []any, this will allow following usage:

return errhelper.WithMetadata(err, errMetadata.Extend("key1", "value1"))

This will call WithMetadata() function with only one key of type Metadata{"key1", "value1"} which is not what we want.

Using []string enforce that you have expanded the returned slice and use following instead:

return errhelper.WithMetadata(err, errMetadata.Extend("key1", "value1")...)

Signed-off-by: Emruz Hossain <[email protected]>
@hossainemruz hossainemruz merged commit eea27ad into main Mar 10, 2025
2 checks passed
@hossainemruz hossainemruz deleted the feat/emruz/add-error-package branch March 10, 2025 14:57
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