On Sun, Jun 19, 2022 at 11:11 PM TheDiveO <
harald....@gmx.net> wrote:
>
> if I understand the linked proposal correct then it is about wrapping multiple errors. I'm unsure how this relates to my question about having separate error types as to differentiate them, and each type always only wraps a single error. How do I connect the dots?
It seemed like a similar concept to me. Likely I misunderstood. Apologies.
One way to write code similar to what you wrote above is
type WrappingError struct {
msg string
err error
}
func (w *WrappingError) Error() string {
return w.msg
}
func (w *WrappingError) Unwrap() error {
return w.err
}
type AErr struct{ *WrappingError }
type BErr struct{ *WrappingError }
func New[T ~struct{ *WrappingError }](msg string, err error) error {
e := T{&WrappingError{msg: msg, err: err}}
return error(e)
}
Ian
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
golang-nuts...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/2c284149-7053-4f94-8903-3cfd7288a935n%40googlegroups.com.