Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2704

Replace all input validation error constants with "InvalidArgumentError"

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • 2.1.0
    • Affects Version/s: None
    • Component/s: None
    • None

      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)
      }
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            matt.dale@mongodb.com Matt Dale
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: