-
Notifications
You must be signed in to change notification settings - Fork 644
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
Implement nested error message handling for schema validation #13045
base: master
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThe code has been updated in the SchemaValidator class to improve error message handling during schema validation. A new private method, Changes
Sequence Diagram(s)sequenceDiagram
participant Handler as handleRequest/handleResponse
participant Validator as SchemaValidator
participant Msg as ValidationReport.Message
Handler->>Validator: Invoke getErrorMessage(topLevelMessage)
Validator->>Msg: Check for nested errors
alt Nested errors exist
Validator->>Validator: Recursively call getErrorMessage(nestedMessage)
end
Validator->>Validator: Construct comprehensive error message
Validator->>Validator: Remove trailing comma and space
Validator->>Handler: Return formatted error message
Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/security/SchemaValidator.java (1)
122-132
: Well-implemented recursive error message concatenation.The
getErrorMessage
method elegantly handles nested validation errors through recursion. The implementation correctly:
- Returns the base message when no nested messages exist
- Recursively processes all nested messages when present
- Properly formats the combined message with appropriate separators
This addresses the original issue where only the first error message was being returned to users, providing a much better debugging experience.
Consider adding a safeguard against extremely deep recursion (though unlikely in practice) to prevent potential stack overflow:
private String getErrorMessage(ValidationReport.Message message){ + return getErrorMessage(message, 0); +} + +private String getErrorMessage(ValidationReport.Message message, int depth){ + // Prevent extremely deep recursion (adjust max depth as needed) + if (depth > 100) { + return message.getMessage() + " [max depth reached]"; + } if(message.getNestedMessages().isEmpty()){ return message.getMessage(); } StringBuilder combinedMessages = new StringBuilder(); combinedMessages.append(message.getMessage()); for (ValidationReport.Message nestedMessage : message.getNestedMessages()) { - combinedMessages.append(", ").append(getErrorMessage(nestedMessage)); + combinedMessages.append(", ").append(getErrorMessage(nestedMessage, depth + 1)); } return combinedMessages.toString().trim(); }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/security/SchemaValidator.java
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: build-product (4, group4)
- GitHub Check: build-product (2, group2)
- GitHub Check: run-benchmark-test
- GitHub Check: build-carbon
- GitHub Check: build-product (1, group1)
- GitHub Check: build-product (3, group3)
🔇 Additional comments (2)
components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/security/SchemaValidator.java (2)
81-86
: Improved error message handling in request validation.The change now properly concatenates all error messages including nested ones, providing more comprehensive feedback to API users. The cleanup of trailing commas and spaces makes the error messages more readable.
108-113
: Consistent implementation of error message handling in response validation.Good to see the same error message handling approach applied to both request and response validation paths, ensuring consistency in the error reporting mechanism.
Purpose
The schema validator in the apimgt.gateway no longer returns the full error message to the user. Only the first error in the validation report is sent. This needs to be fixed.
Implementation Details
A function getErrorMessage() is implemented where it recursively checks whether the ValidationReport.Message has nested messages and get the concatenated message as the result. This fix has been added to both the handleRequest and handleResponse flows.
Related To
wso2/api-manager#3585