-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(analyzer): recognize custom error values in return (#102)
--------- Co-authored-by: xobotyi <[email protected]>
- Loading branch information
1 parent
7ae7de4
commit 5f38877
Showing
5 changed files
with
127 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package j | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
type Test struct { | ||
A string | ||
} | ||
|
||
type AError struct{} | ||
|
||
func (AError) Error() string { return "error message" } | ||
|
||
type BError struct{ msg string } | ||
|
||
func (e BError) Error() string { return e.msg } | ||
|
||
func shouldPassEmptyStructWithConcreteAError() (Test, *AError) { | ||
return Test{}, &AError{} | ||
} | ||
|
||
func shouldFailEmptyStructWithEmptyBError() (Test, error) { | ||
return Test{}, &BError{} // want "j.BError is missing field msg" | ||
} | ||
|
||
func shouldFailEmptyStructWithNilConcreteError() (Test, *BError) { | ||
return Test{}, nil // want "j.Test is missing field A" | ||
} | ||
|
||
func shouldPassEmptyStructWithFmtError() (Test, error) { | ||
return Test{}, fmt.Errorf("error message") | ||
} | ||
|
||
func shouldPassStaticError() (Test, error) { | ||
return Test{}, os.ErrNotExist | ||
} | ||
|
||
func shouldPassAnonymousFunctionReturningError() (Test, error) { | ||
return Test{}, func() error { return nil }() | ||
} | ||
|
||
func shouldFailAnonymousFunctionReturningEmptyError() (Test, error) { | ||
fn := func() error { return &BError{} } // want "j.BError is missing field msg" | ||
|
||
return Test{}, fn() | ||
} | ||
|
||
func shouldFailEmptyNestedStructWithNonNilErr() ([]Test, error) { | ||
return []Test{{}}, os.ErrNotExist // want "j.Test is missing field A" | ||
} |