[DOCS-14028] Investigate changes in SERVER-51839: Add error context when document validator with $expr fails by throwing an exception Created: 03/Dec/20  Updated: 13/Nov/23  Resolved: 19/Mar/21

Status: Closed
Project: Documentation
Component/s: manual, Server
Affects Version/s: None
Fix Version/s: 4.9.0, Server_Docs_20231030, Server_Docs_20231106, Server_Docs_20231105, Server_Docs_20231113

Type: Task Priority: Major - P3
Reporter: Backlog - Core Eng Program Management Team Assignee: Naomi Pentrel (Inactive)
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
documents SERVER-51839 Add error context when document valid... Closed
Participants:
Days since reply: 2 years, 46 weeks, 5 days ago
Epic Link: DOCSP-9747
Story Points: 2

 Description   

Description

Downstream Change Summary

Document validators which use $expr will now generate detailed errors
when $expr throws (for example, the validator {$expr: {$divide: [10,0]}} will always result in a division by zero exception). When the validationAction is set to error, the write will fail with a DocumentValidationError instead of the exception's error code. When the validationAction is set to warn, the write will be accepted and a detailed error will be logged (previously, these writes were rejected).

Description of Linked Ticket

The evaluation of an $expr can throw query-fatal exceptions in a variety of conditions, with one classic example being division by zero. When this happens during the evaluation of a collection validator, the insert or update operation will be rejected by the validator. For example, let's suppose that we create a collection validator that always divides by zero:

 > db.createCollection("c", {validator: {$expr: {$divide: [10, 0]}}})
{ "ok" : 1 }
 > db.c.insert({})
WriteResult({
	"nInserted" : 0,
	"writeError" : {
		"code" : 16608,
		"errmsg" : "can't $divide by zero"
	}
})

The insert is rejected when the system runs the validator to ensure that the write is valid, and the validator itself fails.

Note, however, that the error message doesn't indicate that the problem occurred when checking the document validator. We should add context to the error message so that it says something like "Document validation failed :: caused by :: can't $divide by zero".

As an implementation note, we have a convenient method for adding context to an exception before rethrowing it.

Scope of changes

This might just be a release notes update (heading like Improved $expr Error Handling). But we should review the $expr docs to see if there's anything we need to tweak.

Impact to Other Docs

MVP (Work and Date)

Resources (Scope or Design Docs, Invision, etc.)



 Comments   
Comment by Naomi Pentrel (Inactive) [ 19/Mar/21 ]

This will be covered in the changelog. No other changes are required.

Generated at Thu Feb 08 08:09:19 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.