[GODRIVER-2704] Replace all input validation error constants with "InvalidArgumentError" Created: 16/Dec/22  Updated: 08/Jan/24

Status: Backlog
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 2.0.0

Type: Improvement Priority: Unknown
Reporter: Matt Dale Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to GODRIVER-1854 Make "ErrNilDocument" and "ErrNilValu... Backlog
Epic Link: Go Driver 2.0: Driver

 Description   

There are currently a bunch of error constants (i.e. exported variables of type error) that we expose to allow users to check specific errors. However, users rarely want to check for invalid input at runtime because there's usually no way to remedy those. For example, if you pass "*" as the "name" to IndexView.DropOne you'll get a mongo.ErrMultipleIndexDrop. The only way to remedy that error is to pass a different string value for "name". It's unexpected that a user would be able to write an error handling block that could resolve that type of error, so it's unexpected that a user would check specifically for mongo.ErrMultipleIndexDrop.

Instead, users probably want to be able to check for the entire category of input errors.

E.g. use case of InvalidArgumentError.

var iv mongo.IndexView
 
name := readInput()
_, err := iv.DropOne(ctx, name)
if errors.Is(err, mongo.InvalidArgumentError) {
	fmt.Println("Bad user input: %v", err)
}
if err != nil {
	fmt.Println("Unknown error: %v", err)
}


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