Skip to content

test(internal/librarian/java): use sentinel errors with errors.Is for error validation#5009

Closed
perashanid wants to merge 4 commits into
googleapis:mainfrom
perashanid:fix/java-test-error-check-4962
Closed

test(internal/librarian/java): use sentinel errors with errors.Is for error validation#5009
perashanid wants to merge 4 commits into
googleapis:mainfrom
perashanid:fix/java-test-error-check-4962

Conversation

@perashanid
Copy link
Copy Markdown
Contributor

Address review feedback by replacing string-based error checking with sentinel errors following the project's Go style guide.

Changes:

  • Add errInvalidDistributionName and errAPIConfigNotFound sentinel errors (unexported)
  • 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 #4962

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
@perashanid perashanid requested a review from a team as a code owner April 2, 2026 13:54
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/librarian/java/pom_test.go
@perashanid perashanid force-pushed the fix/java-test-error-check-4962 branch from 19a1185 to 123e5b1 Compare April 2, 2026 14:01
@perashanid
Copy link
Copy Markdown
Contributor Author

perashanid commented Apr 2, 2026

@julieqiu reopened the pr here again , in the earlier i think i messed up with the rebase

here is the orginal pr with rebase problem #4965

@julieqiu julieqiu requested review from noahdietz and zhumin8 April 2, 2026 15:58
Comment thread internal/librarian/java/pom_test.go Outdated
Comment on lines +121 to +123
if err == nil {
t.Fatal("collectModules() error = nil, want non-nil")
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary - errors.Is will handle if err is nil and we'd get collectModules() error = nil, want ...".

Suggested change
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 perashanid requested a review from noahdietz April 2, 2026 21:01
@julieqiu
Copy link
Copy Markdown
Member

julieqiu commented Apr 6, 2026

@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!

@julieqiu julieqiu closed this Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

java: update TestCollectModules_Error to check error

3 participants