errors icon indicating copy to clipboard operation
errors copied to clipboard

Fix match.As to behave the same as errors.As

Open Fryuni opened this issue 3 years ago • 4 comments

Fixes #19

Fryuni avatar Jan 24 '22 21:01 Fryuni

Thanks @Fryuni ! Can you please take a look at the failing tests?

sagikazarmark avatar Jan 26 '22 13:01 sagikazarmark

Sure, they all passed locally on 1.17 🙃, I forgot to try on the previous versions

Fryuni avatar Jan 26 '22 14:01 Fryuni

I fixed the compatibility problems (the %w formatting), but there is a bigger problem here.

errors.As extract the value in the error chain with the target type and assign it to the target pointer, this is useful to get inner data from the matched error. Writing to the pointer it receives makes it not concurrent-safe. To have the same behavior, match.As would also not be concurrent-safe. Since it is tested now to be concurrent, I think changing it would qualify as a breaking change.

I can remove the race test or change just the matching logic to be the same as errors.As without assigning to the pointer. It seems the latter was the intention of the current code but in that case, I think I should add a match.AsAssign/AsShape or something like that

WDYT @sagikazarmark ?

Fryuni avatar Jan 26 '22 15:01 Fryuni

@sagikazarmark just going through my open PRs, any thoughts on this? 😄

Fryuni avatar Feb 03 '22 11:02 Fryuni