Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-207

SafeMode should allow for errors to be handled externally without throwing an exception

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible

      Currently, enabling safe mode (SafeMode.Enabled == true) leads to MongoSafeModeException to be thrown if the command failed. While it's a fine thing to do generally, throwing the exception if the error is expected (think unique constraint violations for example) isn't a good idea in the terms of performance (in .NET under Windows, throwing an exception takes a lot of time, hurts cache, etc.).
      I propose a new flag to be added to SafeMode – SafeMode.Permissive. It should default to false, cannot be set to true unless SafeMode.Enabled is also true (like SafeMode.W can't be set to nonzero value while SafeMode.Enabled isn't true), and the checks that lead to an exception to be thrown inside the MongoConnection.SendMessage() method should only be done if SafeMode.Permissive is false.
      The proposed solution completely preserves backwards compatibility and greatly aids if one wants to examine and handle MongoDB error responses on his own without incurring the performance penalty of catching exceptions while a simple error code check would suffice.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            onyxmaster Aristarkh Zagorodnikov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: