Inspectopedia Help

Incorrect usage of the 'errors.As' function

Reports calls of the errors.As function when the second argument is not a pointer to an interface or to a type that implements an error.

Such calls panic at runtime.

For more information about the As function, refer to func As at go.dev.

Example:

_, err := os.Open("non-existing") var pathError *fs.PathError if errors.As(err, pathError) { // a pointer to *fs.PathError is required }

After the Prepend '&' quick-fix is applied:

_, err := os.Open("non-existing") var pathError *fs.PathError if errors.As(err, &pathError) { }

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.

GoErrorsAs
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

This inspection only reports if the language version is 1.13 or higher.

Availability

By default bundled with

GoLand 2024.1, Qodana for Go 2024.1,

Can be installed with plugin

Go, 241.SNAPSHOT

Last modified: 18 June 2024