test(internal/librarian/java): use sentinel errors with errors.Is for error validation#5009
test(internal/librarian/java): use sentinel errors with errors.Is for error validation#5009perashanid wants to merge 4 commits into
Conversation
Address review feedback from PR googleapis#4965 by replacing string-based error checking with sentinel errors following the project's Go style guide. Changes: - Add ErrInvalidDistributionName and ErrAPIConfigNotFound sentinel errors - Wrap sentinel errors in collectModules error returns using %w - Update TestCollectModules_Error to use errors.Is instead of strings.Contains - Remove unused strings import from test file This makes error checking more robust and maintainable by avoiding fragile string comparisons that can break when error messages change. Fixes googleapis#4962
There was a problem hiding this comment.
Code Review
This pull request refactors error handling in the Java librarian by introducing sentinel errors for invalid distribution names and missing API configurations, updating the code to wrap these errors and the tests to verify them using errors.Is. A critical issue was identified in pom_test.go where a merge conflict marker and duplicate code were left in the file, which results in invalid syntax and must be resolved.
19a1185 to
123e5b1
Compare
| if err == nil { | ||
| t.Fatal("collectModules() error = nil, want non-nil") | ||
| } |
There was a problem hiding this comment.
This isn't necessary - errors.Is will handle if err is nil and we'd get collectModules() error = nil, want ...".
| if err == nil { | |
| t.Fatal("collectModules() error = nil, want non-nil") | |
| } |
errors.Is handles nil errors correctly, so the explicit nil check is redundant.
|
@perashanid - thanks for the contributions. Our internal development is moving so quickly at this point that external PRs are likely to fall out of sync almost immediately, making it difficult for us to review and integrate external contributions effectively. For that reason, we’ve decided to keep development internal for the time being. I'm going to close this out to save you any further effort on updates. We appreciate the initiative regardless! |
Address review feedback by replacing string-based error checking with sentinel errors following the project's Go style guide.
Changes:
This makes error checking more robust and maintainable by avoiding fragile string comparisons that can break when error messages change.
Fixes #4962