An error is identified by comparing its message with a constant string

tx0/go:error-text-comparisonrecommendedwarningbug

What it finds

if err.Error() == "record not found": the text of an error is meant for people, and libraries change it, add context to it or wrap the error, after which the comparison quietly stops matching. errors.Is with a sentinel error, or errors.As with an error type, compares what the error is.

Reported are comparisons with == or != between a call of a method Error without arguments and a constant string.

From the rule's source, error_text_comparison.rs.

Example from the rule's tests
package p import "errors" var errMissing = errors.New("missing") func f(err error) bool {	if err.Error() == "record not found" {tx0 reports: an error is identified by its message		return true	}	return errors.Is(err, errMissing) || err.Error() != ""tx0 reports: an error is identified by its message}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/go:error-text-comparison" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/go:error-text-comparison] reason="..."

tx0 explain tx0/go:error-text-comparison shows the same in the terminal. Found a false positive? Report it.