Inspectopedia 2025.2 Help

Direct comparison of errors

Reports direct comparison of errors, for example, using ==, and suggests using errors.Is instead.

Since Go 1.13, errors can be wrapped using the fmt.Errorf function with the %w verb. Therefore, direct comparison of errors using the equality check fails on wrapped errors. The preferred way of checking for a specific error is to use the errors.Is function from the standard library as this function traverses the chain of the wrapped errors while checking for a specific error.

For more information about errors.Is, refer to working with Errors in Go 1.13.

The quick-fix replaces direct comparison of errors with a call to errors.Is.

Example:

if err == MyError { fmt.Println("MyErr") }

After the quick fix is applied:

if errors.Is(err, MyError) { fmt.Println("MyErr") }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

GoDirectComparisonOfErrors
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Go | Probable bugs

Inspection ID: GoDirectComparisonOfErrors

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection GoDirectComparisonOfErrors

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

GoLand 2025.2, Qodana for Go 2025.2,

Can be installed with plugin:

Go, 252.26654.0

Last modified: 18 September 2025