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, see 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) {
}
This inspection only reports if the language version is 1.13 or higher.
Inspection Details | |
---|---|
Available in: | GoLand 2023.3 |
Plugin: | Go, 233.SNAPSHOT |
Last modified: 13 July 2023