-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(analyzer): recognize custom error values in return #102
feat(analyzer): recognize custom error values in return #102
Conversation
This commit adds ability to recognize return of custom error literals under [error] interface type, e.g., ```golang package example type S struct { i int s string } type CustomError struct { msg string } func (e CustomError) Error() string { return e.msg } func returnCustomError_1() (S, error) { return S{}, &CustomError{msg: "error message"} // Ok } func returnCustomError_2() (S, error) { return S{}, &CustomError{} // Warning: example.CustomError is missing field msg } func returnCustomError_3() (S, error) { return S{}, nil // Warning: example.S is missing fields i, s } ```
Here are the results of running the old and new versions of exhaustruct on the k8s repository.
|
…s out of the loop
containsNonNilValOfErrType => containsErrorIfaceValue containsNonNilValUnderErrType => containsValUnderErrorIface
Thank you for pull request, first of all. It is definely a step towards #89, but slightly in wrong direction, as it still implies that function should return an I will commit to your pullrequest, but change the code, reusing testcases. |
Drastically simplify error fields detection, slightly changing the way these cases are handled. Now, in case return statement contains types that satisfies `error` interface - only those types will be checked (in case they're structures too).
@ruslanSorokin @navijation - pushed the version. All details can be found in tests and readme. This solution is way simpler that one proposed by Ruslan. Also i trimmed tests a bit, leaving only ones that cover cornercases of errors handling. |
As for diff - it handles more false positives on kubernetes repo |
Yeah, I definitely took the wrong approach which also gives less functionality. Thanks for taking the time to revise it. |
This commit adds ability to recognize return of custom error values on the position of [error] interface type, e.g.,