On Wed, Sep 2, 2020 at 12:20 PM 'simon place' via golang-nuts <golang-nuts@googlegroups.com> wrote: > > OK, i think i have it; > > basically he root of it was i wasn't thinking properly about how errors > need/should be implemented as immutable. Unwrap is basically a state getter. > (no setter for the wrapped error.) > > so it seems to me that custom and fmt.Prinf("%w") wrappers have different use > cases:
%w is not a formatting verb, so fmt.Prinf("%w") is not valid. Instead of creating a separate MyErr struct, you could've done: err1:= errors.New("error") err1= fmt.Errorf("fmt wrapping: %w",err1) fmt.Println(err1) err2:=errors.New("error") err3= fmt.Errorf("Wrapped: %w",err2) // Here, err3 is an error wrapping err2 fmt.Println(err3) > > * fmt.Printf(%w) is just to add more text to an error, because errors are > immutable its needed.(unless you have custom error types and are local to > them, then you could just edit their state.) > > * custom wrapping types, unlike fmt.Printf(%w), create error 'classes' for > testing against and have utilities to help deal with unknown depths of > wrapping. > > since i was only dealing with one level, i probably should have avoided > wrapping entirely, but now i know! > > this does seem as if its a pattern that might come up elsewhere, so good to > understand clearly (unless i'm still off about something above). > > thanks for help. > > -- > 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/fa0e1186-c185-4143-9df9-d0ba7aa11826o%40googlegroups.com. -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAMV2RqrAGc8LTQ3QTDt%3DL9uaD0L%2BQjfRyobiNJymgQRLqUWJ3w%40mail.gmail.com.