This may not be the exact answer you're looking for, but there's a package
which handles this even better than Go's builtin error package:
https://github.com/pkg/errors
Dave Cheney's package is better designed, IMO, and the explicit
errors.Wrap() call is more clear than inferring it from your for
I think that in general you will have to only use features available to Go
1.11, meaning, of course, that the new methods in the errors package would
be off limits. In the mean time you could use golang.org/x/xerrors, which
is a superset of the new errors package and I believe will work with 1.11.