From 0e52b903c75308e2bf4fdfe6c46b164cdee05d4e Mon Sep 17 00:00:00 2001 From: Nicholas Zolnierz Date: Mon, 8 Nov 2021 08:22:01 -0500 Subject: SERVER-61307 Add context to 'partitionBy' optimization errors --- src/mongo/db/pipeline/document_source_set_window_fields.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/mongo/db/pipeline/document_source_set_window_fields.cpp b/src/mongo/db/pipeline/document_source_set_window_fields.cpp index 0f15a20593f..a02c693f391 100644 --- a/src/mongo/db/pipeline/document_source_set_window_fields.cpp +++ b/src/mongo/db/pipeline/document_source_set_window_fields.cpp @@ -181,7 +181,15 @@ list> document_source_set_window_fields::create( // If partitionBy is a more complex expression, we will need to generate a $set stage, // which will bind the value of the expression to the name in simplePartitionBy. if (partitionBy) { - partitionBy = (*partitionBy)->optimize(); + // Catch any failures that may surface during optimizing the partitionBy expression and add + // context. This allows for the testing infrastructure to detect when parsing fails due to + // a new optimization, which passed on an earlier version without the optimization. + try { + partitionBy = (*partitionBy)->optimize(); + } catch (DBException& ex) { + ex.addContext("Failed to optimize partitionBy expression"); + throw; + } if (auto exprConst = dynamic_cast(partitionBy->get())) { uassert(ErrorCodes::TypeMismatch, "An expression used to partition cannot evaluate to value of type array", -- cgit v1.2.1