Go
Incorrect usage of the 'errors.As' function
Warning
Reliability
New
Last modified: 03 December 2024 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) {
}
- 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
This inspection only reports if the language version is 1.13 or higher.
Inspection Details | |
---|---|
By default bundled with: | |
Can be installed with plugin: | Go, 243.23131 |
Thanks for your feedback!
Was this page helpful?