Replace printStackTrace with log.error for exceptions#27674
Replace printStackTrace with log.error for exceptions#27674Branavan2004 wants to merge 1 commit into
Conversation
📝 WalkthroughChanges SummaryThis PR refactors exception handling in the Key Changes
ImpactThis change integrates identity recovery errors with WSO2's standard logging framework, enabling better monitoring, filtering, and management of error logs alongside other application logs rather than having them scattered across console output. WalkthroughThe 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
modules/integration/tests-common/admin-clients/src/main/java/org/wso2/identity/integration/common/clients/mgt/UserInformationRecoveryServiceClient.java (1)
65-65: Consider adding operation context to error logsAll catches currently emit the same message. Including the operation name (for example,
verifyUser,updatePassword) would make troubleshooting faster without changing behavior.Proposed minimal refactor pattern
- log.error("An error occurred during user information recovery service invocation", e); + log.error("Failed to invoke UserInformationRecoveryService#verifyUser", e);Also applies to: 75-75, 85-85, 96-96, 107-107, 117-117, 128-128, 139-139, 149-149, 159-159, 170-170, 181-181, 192-192
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@modules/integration/tests-common/admin-clients/src/main/java/org/wso2/identity/integration/common/clients/mgt/UserInformationRecoveryServiceClient.java` at line 65, The catch blocks in UserInformationRecoveryServiceClient currently log a generic message; update each catch to include the specific operation context (e.g., "verifyUser", "updatePassword", and other method names in this class) in the log message so errors read like "Error during <operationName> invocation" and still pass the exception object (e) to log.error; locate the log.error calls in the catch blocks of methods such as verifyUser and updatePassword and replace the static message with one that embeds the method/operation name for easier troubleshooting.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@modules/integration/tests-common/admin-clients/src/main/java/org/wso2/identity/integration/common/clients/mgt/UserInformationRecoveryServiceClient.java`:
- Line 65: The catch blocks in UserInformationRecoveryServiceClient currently
log a generic message; update each catch to include the specific operation
context (e.g., "verifyUser", "updatePassword", and other method names in this
class) in the log message so errors read like "Error during <operationName>
invocation" and still pass the exception object (e) to log.error; locate the
log.error calls in the catch blocks of methods such as verifyUser and
updatePassword and replace the static message with one that embeds the
method/operation name for easier troubleshooting.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 42b3a395-2cb2-4f83-b119-94e25687edc3
📒 Files selected for processing (1)
modules/integration/tests-common/admin-clients/src/main/java/org/wso2/identity/integration/common/clients/mgt/UserInformationRecoveryServiceClient.java
|




Description
This PR addresses a code smell in
UserInformationRecoveryServiceClient.java. The integration client previously handled exceptions by callinge.printStackTrace()14 separate times. This is an anti-pattern that causes unstructured stack traces to leak directly into the console, bypassing the centralized logging framework and making it harder to filter logs.Changes Made
org.apache.commons.logging.Log.private static final Log log = LogFactory.getLog(UserInformationRecoveryServiceClient.class);e.printStackTrace()calls with proper error logging:log.error("An error occurred during user information recovery service invocation", e);.This minor refactoring ensures that all identity recovery errors safely flow through WSO2's standard logging pipelines.