An error is inspected with a type assertion, which misses wrapped errors

tx0/go:error-type-assertedstrictwarningreliability/error-handlingdepth fastsmell

What it finds

if pe, ok := err.(*os.PathError); ok: a type assertion looks only at the error itself, so as soon as a caller wraps it with fmt.Errorf("...: %w", err) the assertion fails and the handling is skipped. errors.As(err, &pe) searches the whole chain.

Reported are type assertions to a type other than an interface written as a literal, and type switches, on a variable named err or ending in Err or err.

From the rule's source, error_type_asserted.rs.

Example from the rule's tests
package p import "os" func missing(err error) bool {	if _, ok := err.(*os.PathError); ok {tx0 reports: a type assertion on an error misses wrapped errors		return true	}	return false}
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 strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/go:error-type-asserted" = "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-type-asserted] reason="..."

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