I think it is no different from regular "if err != nil {}" handling, sorry
My thought behind ? is to make is working for a simple cases. If you are doing an error translation/transform/wrapping - this is a case that I feel is better handled by existing explicit "if err != nil" construct. A. On Sunday, June 30, 2019 at 3:12:18 AM UTC-6, mh cbon wrote: > > f := file.Open() ? error { > //f is nill > return erors.Wrap("nop",err) > } > defer f.Close() > > On Saturday, June 29, 2019 at 11:56:09 PM UTC+2, Andrey Tcherepanov wrote: >> >> Hello mighty fighters of errors! >> >> Here comes my half-thought idea of another way to express error handling: >> >> *Add a postfix '?' that checks value for **emptiness (nil, 0, "") **AND >> an error for nil. * >> >> (Denis have shred it to pieces already in >> https://github.com/golang/go/issues/32852. Thank you Denis.) >> >> I am not good with expressing my inner talk, so there are couple examples >> >> original , Go 1 function >> >> func stat(filename string) (os.FileInfo, error) { >> >> var info os.FileInfo >> { >> var a1 *os.File >> if a1, err := os.Open(filename); err != nil || a1 == nil { >> return _, err >> } >> var a2 os.FileInfo >> if a2, err := a1.Stat(); err != nil || a2 == nil { >> return _, err >> } >> info = a2 >> } >> return info, nil >> } >> >> >> And with "?", trying to avoid original try() proposal handle leak >> >> // would return _, err, but since there is no err in signature, will return >> default value in case of error >> // uses ? on func call that returns (value, error) >> func stat2(filename string) (os.FileInfo) { >> file := os.Open(filename)? >> defer file.Close() >> return file.Stat()? >> } >> // would return error too, uses ? as "not nil" on a variable too >> func stat3(filename string) (_ os.FileInfo, err error) { >> var file *os.File >> defer file?.Close() >> file := os.Open(filename)? >> return file.Stat() >> } >> >> >> Thoughts? >> > -- 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/e71bc0cc-61d7-4f3c-ab3f-5972c87b6663%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.