Preparing go 1.12 code for error changes in go 1.13

345 views
Skip to first unread message

ma...@influxdata.com

unread,
Mar 12, 2019, 6:09:53 PM3/12/19
to golang-dev
Consider the following test on playground: https://play.golang.org/p/PQuDmwMF5DG

There are two separate calls to errors.New, with an identical string argument.
Calling reflect.DeepEqual on those two error values returns true in 1.12 but false in tip (go version devel +01d1dc4172 Tue Mar 12 21:08:33 2019 +0000 darwin/amd64).

Some of the code bases I work in, have test suites that are passing on 1.12 but failing on tip
because they call reflect.DeepEqual on error values like the above example.

I'm pretty sure I've seen, in the past, recommendations against using reflect.DeepEqual with types you don't own.
So, fair enough, we shouldn't have been using reflect.DeepEqual with values returned from fmt.Errorf or errors.New.
go-cmp also reports that err1 and err2 are no longer considered cmp.Equal(), seemingly due to the new frame pointer information stored in errors.
(At least with whichever version of go-cmp we're using in those projects.)

It looks like the standard library tests comparing errors have changed from comparing err1 and err2, to comparing err1.Error() with err2.Error().

I'm mainly looking for confirmation -- is comparing the result of the Error method the preferred comparison approach for transitioning from go1.12 to tip/go1.13?

But I also wanted to post this as an early heads-up that end-users will likely have broken tests as the 1.13 beta comes around in a few months.
And I didn't find any other search results on the mailing lists discussing this yet.
I debated posting to golang-nuts, but I decided on golang-dev based on how early the 1.13 cycle is as of today.

Thanks,
Mark

Ian Davis

unread,
Mar 12, 2019, 9:21:43 PM3/12/19
to golan...@googlegroups.com
On Tue, 12 Mar 2019, at 10:09 PM, ma...@influxdata.com wrote:
Consider the following test on playground: https://play.golang.org/p/PQuDmwMF5DG

There are two separate calls to errors.New, with an identical string argument.
Calling reflect.DeepEqual on those two error values returns true in 1.12 but false in tip (go version devel +01d1dc4172 Tue Mar 12 21:08:33 2019 +0000 darwin/amd64).

Some of the code bases I work in, have test suites that are passing on 1.12 but failing on tip
because they call reflect.DeepEqual on error values like the above example.

There is a very long ongoing thread about this on the Go 2 Error Values issue, with some relevant recent discussion here: https://github.com/golang/go/issues/29934#issuecomment-472148465

Ian



ma...@influxdata.com

unread,
Mar 13, 2019, 11:43:05 AM3/13/19
to golang-dev
Thanks -- I missed that one because I don't tend to keep up with Go 2 proposals or threads with hundreds of replies.

Skimming over it, it looks like there isn't a resolution yet, which is fine.
At least in the meantime anyone else who searches who does a mailing list search
should stumble across that thread now.
Reply all
Reply to author
Forward
0 new messages