CSHARP-5928: LINQ Provider throws misleading exception if expression translation is not supported#1915
Conversation
…translation is not supported
|
|
||
| public static TranslatedExpression TranslateWithoutUnwrapping(TranslationContext context, Expression expression) | ||
| { | ||
| if (!context.HasResultSerializer(expression)) |
There was a problem hiding this comment.
We should not validate it here, because serializer could be missing for different reasons here (it could be either not supported combination of parameters for known-expression, non-translatable expression, or simply not implemented yet expression).
| { | ||
| if (!context.HasResultSerializer(expression)) | ||
| { | ||
| throw new ExpressionNotSupportedException(expression); |
There was a problem hiding this comment.
It does not really matter what we throws here as we will try fallback to expression language on line 45.
There was a problem hiding this comment.
Pull request overview
This PR improves LINQ3 error reporting so that when an expression can’t be translated, the driver throws an ExpressionNotSupportedException that points at the unsupported expression rather than a misleading “couldn’t determine serializer” message.
Changes:
- Added an integration test covering the Jira case (CSHARP-5928) and asserting the unsupported sub-expression appears in the exception message.
- Adjusted filter translation to allow falling back to aggregation-operator translation even when a result serializer can’t be determined up-front.
- Removed the up-front “must have result serializer” guard from aggregation-expression translation and added a targeted serializer validity check in
TranslatedExpression.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp5928Tests.cs | Adds regression test asserting the thrown exception message references the unsupported Replace(...) expression. |
| src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/ExpressionToFilterTranslator.cs | Moves the “has result serializer” check into the try-path so failures can fall back to aggregation translation. |
| src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/ExpressionToAggregationExpressionTranslator.cs | Removes the up-front serializer guard to avoid masking real translation failures. |
| src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/TranslatedExpression.cs | Validates result serializer isn’t an ignore/unknowable marker before storing it. |
| src/MongoDB.Driver/Linq/Linq3Implementation/Misc/SerializationHelper.cs | Adds EnsureValidResultSerializer helper used by TranslatedExpression. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
src/MongoDB.Driver/Linq/Linq3Implementation/Misc/SerializationHelper.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
No description provided.