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

Proposal: Support for error types #238

Closed
jurajkulich opened this issue Nov 22, 2022 · 5 comments
Closed

Proposal: Support for error types #238

jurajkulich opened this issue Nov 22, 2022 · 5 comments

Comments

@jurajkulich
Copy link

Hello,
At the moment, it's not possible to differentiate errors via error types. This could help determine the error directly instead of using, e.g. strings.Contains.

For example:

if err := env.Parse(c); err != nil {
	if err == env.ErrMissingRequired {
	}
	if err == env.ErrEmpty {
	}
}
@akutuev
Copy link
Contributor

akutuev commented Nov 22, 2022

@caarlos0 should I take a look at that improvement?

@caarlos0
Copy link
Owner

ah, this is a good one indeed

yes @akutuev feel free to take a hit at it

thanks everyone!

@akutuev
Copy link
Contributor

akutuev commented Dec 3, 2022

Hello all,

I did some brief investigations and let me put my input here: Due to our new improvement #208 (and its PR #233) we aggregate multiple errors (even with multiple types) to be able to provide a single aggregated message for a user. Therefore to identify the error type we have to iterate over the list of errors.

If it makes sense, The user should:

  1. Covert type of the Parse/ParseWithFunc error as AggregateError to get access to the list of errors
  2. Iterate over errors to get a specific type of the error

In general, this approach won't lead to breaking changes but might bring some complexity

@caarlos0 @jurajkulich Happy to get your opinion

@caarlos0
Copy link
Owner

caarlos0 commented Dec 3, 2022

@akutuev that sounds good yes!

I wonder if we should wait to see how the aggregate errors are looking like in go 1.20... haven't looked much into it yet, but maybe it makes this easier...

@caarlos0
Copy link
Owner

caarlos0 commented Feb 7, 2023

merged #240

@caarlos0 caarlos0 closed this as completed Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants