Conversation
📝 WalkthroughWalkthroughAdds targeted XML parsing detection for prolog/trailing-section Transformer/XPath errors, enriches ExchangeExpressionException with contextual messages and fluent metadata (body/extension/exclude), changes flow invocation to abort on expression failures, adds StringUtil truncate/tail helpers and tests, and implements ProblemDetails.toString(). Changes
Sequence DiagramssequenceDiagram
participant Client
participant XPathEngine as XPath / XSLT Engine
participant ExprEvaluator as ExchangeExpressionEvaluator
participant FlowController as InterceptorContainer
participant ProblemBuilder as ProblemDetails/Response
Client->>ExprEvaluator: submit exchange with XML body
ExprEvaluator->>XPathEngine: parse/evaluate XPath/XSLT
XPathEngine-->>ExprEvaluator: throws Transformer/XPath exception
ExprEvaluator->>ExprEvaluator: inspect nested cause messages
alt "not allowed in prolog" or "is not allowed in trailing section"
ExprEvaluator->>ProblemBuilder: build ExchangeExpressionException(detail + truncated/tail body)
ExprEvaluator->>FlowController: return ABORT
FlowController->>ProblemBuilder: assemble production-safe ProblemDetails (respect excludeException)
ProblemBuilder-->>Client: send error response
else other error
ExprEvaluator->>ProblemBuilder: create standard ExchangeExpressionException
ExprEvaluator->>FlowController: propagate per existing flow (may createErrorResponse)
FlowController->>ProblemBuilder: assemble response
ProblemBuilder-->>Client: send error response
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
|
This pull request needs "/ok-to-test" from an authorized committer. |
|
/ok-to-test |
…SONPath, and SpEL expressions - Centralized handling of exceptions in XPath and JSONPath expressions. - Enhanced error messages for unmapped XML prefixes and invalid JSONPath exceptions. - Introduced `tail` method in `StringUtil` for handling detailed error outputs. - Improved test coverage for corner cases in expression evaluations.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@core/src/main/java/com/predic8/membrane/core/lang/jsonpath/JsonpathExchangeExpression.java`:
- Around line 101-107: The getErrorMessageForJsonPath method in
JsonpathExchangeExpression currently embeds request body content into the
exception message; change it to return a generic error message (e.g., "Error
evaluating Jsonpath %s.") instead of including the body and move the body
content into the ExchangeExpressionException body for internal diagnostics (use
the same pattern as XPathExchangeExpression). Specifically, update
getErrorMessageForJsonPath to avoid including truncateAfter(body, 200) in the
returned string and ensure wherever ExchangeExpressionException is created for
JsonpathExchangeExpression you call .body(body) (or equivalent) on the exception
so internal logs have the body but clients only see the generic message.
🧹 Nitpick comments (4)
core/src/main/java/com/predic8/membrane/core/util/text/StringUtil.java (1)
29-43: Consider adding validation for negativemaxLengthvalues.Both
truncateAfterandtailmethods don't handle negativemaxLengthinputs.truncateAfterwould throwStringIndexOutOfBoundsExceptionifmaxLength < 0, andtailwould return the full string (unintended behavior). If defensive validation is desired:♻️ Optional: Add parameter validation
public static String truncateAfter(String s, int maxLength) { + if (maxLength < 0) throw new IllegalArgumentException("maxLength must be non-negative"); return s.substring(0, min(s.length(), maxLength)); } public static String tail(String s, int maxLength) { + if (maxLength < 0) throw new IllegalArgumentException("maxLength must be non-negative"); return s.substring(Math.max(s.length() - maxLength,0)); }core/src/test/java/com/predic8/membrane/core/util/text/StringUtilTest.java (1)
10-15: Consider expanding test coverage.The test covers basic
tailscenarios but is missing:
- Tests for
truncateAftermethod (also newly added)- Edge case:
maxLength = 0♻️ Suggested additional tests
`@Test` void testTail() { assertEquals("def", tail("abcdef",3)); assertEquals("abcdef", tail("abcdef",10)); assertEquals("", tail("",10)); + assertEquals("", tail("abcdef", 0)); +} + +@Test +void testTruncateAfter() { + assertEquals("abc", truncateAfter("abcdef", 3)); + assertEquals("abcdef", truncateAfter("abcdef", 10)); + assertEquals("", truncateAfter("", 10)); + assertEquals("", truncateAfter("abcdef", 0)); }Don't forget to add the import:
import static com.predic8.membrane.core.util.text.StringUtil.truncateAfter;core/src/main/java/com/predic8/membrane/core/lang/xpath/XPathExchangeExpression.java (1)
68-68: Consider a more professional error message.The message "Should not Happen!" is informal for production code. A more descriptive message would aid debugging.
♻️ Suggested fix
- throw new RuntimeException("Should not Happen!"); + throw new RuntimeException("Unsupported evaluation type: " + type.getName());core/src/main/java/com/predic8/membrane/core/lang/jsonpath/JsonpathExchangeExpression.java (1)
85-98: Include the throwable in logs to preserve stack traces.Right now only the formatted message is logged, which drops the exception context needed for debugging.
♻️ Suggested tweak (preserve stack traces)
- log.error(msg); + log.error(msg, ipe); @@ - log.info(msg); + log.info(msg, e); @@ - log.info(msg); + log.info(msg, e);
Summary by CodeRabbit
Bug Fixes
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.