proposal: errors: document what errors.Is(x, nil) means #73122
Labels
Documentation
Issues describing a change to documentation.
LibraryProposal
Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool
Proposal
Milestone
Proposal Details
Given the current implementation of
errors.Is
, doingerr != nil
is equivalent to!errors.Is(err, nil)
. Theerr != nil
is arguably often better: it is shorter, perhaps faster, and a common Go idiom. But there are occasions where usingnil
arguments toerrors.Is
makes sense.One such example is test code. You might have a list of input and expected outputs of a function under test. If the function returns an error
err
, it makes sense to useif !errors.Is(err, expected_error) { return ErrWrongError }
, even ifexpected_error
isnil
.This currently works, but the behavior is not documented. In both #40442 and #40673 it was suggested that this should be documented, but apparently that never happened.
I propose that the current behavior is documented. Proposal: add one sentence in the first paragraph, so that it becomes:
The text was updated successfully, but these errors were encountered: