func (bwe BulkWriteException) HasErrorCodeWithMessage(code int, message string) bool {
	if bwe.WriteConcernError != nil &&
		bwe.WriteConcernError.Code == code && strings.Contains(bwe.WriteConcernError.Message, message) {
		return true
	}
	for _, we := range bwe.WriteErrors {
		if we.Code == code && strings.Contains(we.Message, message) {
			return true
		}
	}
	return false
}
HasErrorCodeWithMessage returns true if any of the contained errors have the specified code and message.
package mongo
import (
	"bytes"
	"context"
	"errors"
	"fmt"
	"net"
	"strings"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/x/mongo/driver"
	"go.mongodb.org/mongo-driver/x/mongo/driver/mongocrypt"
	"go.mongodb.org/mongo-driver/x/mongo/driver/topology"
)
var ErrUnacknowledgedWrite = errors.New("unacknowledged write")
var ErrClientDisconnected = errors.New("client is disconnected")
var ErrNilDocument = errors.New("document is nil")
var ErrNilValue = errors.New("value is nil")
var ErrEmptySlice = errors.New("must provide at least one element in input slice")
type ErrMapForOrderedArgument struct {
	ParamName string
}
func (e ErrMapForOrderedArgument) Error() string {
	return fmt.Sprintf("multi-key map passed in for ordered parameter %v", e.ParamName)
}
func replaceErrors(err error) error {
	if err == topology.ErrTopologyClosed {
		return ErrClientDisconnected
	}
	if de, ok := err.(driver.Error); ok {
		return CommandError{
			Code:    de.Code,
			Message: de.Message,
			Labels:  de.Labels,
			Name:    de.Name,
			Wrapped: de.Wrapped,
		}
	}
	if qe, ok := err.(driver.QueryFailureError); ok {
		ce := CommandError{
			Name:    qe.Message,
			Wrapped: qe.Wrapped,
		}
		dollarErr, err := qe.Response.LookupErr("$err")
		if err == nil {
			ce.Message, _ = dollarErr.StringValueOK()
		}
		code, err := qe.Response.LookupErr("code")
		if err == nil {
			ce.Code, _ = code.Int32OK()
		}
		return ce
	}
	if me, ok := err.(mongocrypt.Error); ok {
		return MongocryptError{Code: me.Code, Message: me.Message}
	}
	return err
}
func IsDuplicateKeyError(err error) bool {
	for ; err != nil; err = unwrap(err) {
		if e, ok := err.(ServerError); ok {
			return e.HasErrorCode(11000) || e.HasErrorCode(11001) || e.HasErrorCode(12582) ||
				e.HasErrorCodeWithMessage(16460, " E11000 ")
		}
	}
	return false
}
func IsTimeout(err error) bool {
	for ; err != nil; err = unwrap(err) {
		if err == context.DeadlineExceeded {
			return true
		}
		if ne, ok := err.(net.Error); ok {
			return ne.Timeout()
		}
		if se, ok := err.(ServerError); ok {
			if se.HasErrorLabel("NetworkTimeoutError") || se.HasErrorLabel("ExceededTimeLimitError") {
				return true
			}
		}
	}
	return false
}
func unwrap(err error) error {
	u, ok := err.(interface {
		Unwrap() error
	})
	if !ok {
		return nil
	}
	return u.Unwrap()
}
func IsNetworkError(err error) bool {
	for ; err != nil; err = unwrap(err) {
		if e, ok := err.(ServerError); ok {
			return e.HasErrorLabel("NetworkError")
		}
	}
	return false
}
type MongocryptError struct {
	Code    int32
	Message string
}
func (m MongocryptError) Error() string {
	return fmt.Sprintf("mongocrypt error %d: %v", m.Code, m.Message)
}
type EncryptionKeyVaultError struct {
	Wrapped error
}
func (ekve EncryptionKeyVaultError) Error() string {
	return fmt.Sprintf("key vault communication error: %v", ekve.Wrapped)
}
func (ekve EncryptionKeyVaultError) Unwrap() error {
	return ekve.Wrapped
}
type MongocryptdError struct {
	Wrapped error
}
func (e MongocryptdError) Error() string {
	return fmt.Sprintf("mongocryptd communication error: %v", e.Wrapped)
}
func (e MongocryptdError) Unwrap() error {
	return e.Wrapped
}
type ServerError interface {
	error
	HasErrorCode(int) bool
	HasErrorLabel(string) bool
	HasErrorMessage(string) bool
	HasErrorCodeWithMessage(int, string) bool
	serverError()
}
var _ ServerError = CommandError{}
var _ ServerError = WriteException{}
var _ ServerError = BulkWriteException{}
type CommandError struct {
	Code    int32
	Message string
	Labels  []string  
	Name    string    
	Wrapped error     
}
func (e CommandError) Error() string {
	if e.Name != "" {
		return fmt.Sprintf("(%v) %v", e.Name, e.Message)
	}
	return e.Message
}
func (e CommandError) Unwrap() error {
	return e.Wrapped
}
func (e CommandError) HasErrorCode(code int) bool {
	return int(e.Code) == code
}
func (e CommandError) HasErrorLabel(label string) bool {
	if e.Labels != nil {
		for _, l := range e.Labels {
			if l == label {
				return true
			}
		}
	}
	return false
}
func (e CommandError) HasErrorMessage(message string) bool {
	return strings.Contains(e.Message, message)
}
func (e CommandError) HasErrorCodeWithMessage(code int, message string) bool {
	return int(e.Code) == code && strings.Contains(e.Message, message)
}
func (e CommandError) IsMaxTimeMSExpiredError() bool {
	return e.Code == 50 || e.Name == "MaxTimeMSExpired"
}
func (e CommandError) serverError() {}
type WriteError struct {
	Index int
	Code    int
	Message string
}
func (we WriteError) Error() string { return we.Message }
type WriteErrors []WriteError
func (we WriteErrors) Error() string {
	var buf bytes.Buffer
	fmt.Fprint(&buf, "write errors: [")
	for idx, err := range we {
		if idx != 0 {
			fmt.Fprintf(&buf, ", ")
		}
		fmt.Fprintf(&buf, "{%s}", err)
	}
	fmt.Fprint(&buf, "]")
	return buf.String()
}
func writeErrorsFromDriverWriteErrors(errs driver.WriteErrors) WriteErrors {
	wes := make(WriteErrors, 0, len(errs))
	for _, err := range errs {
		wes = append(wes, WriteError{Index: int(err.Index), Code: int(err.Code), Message: err.Message})
	}
	return wes
}
type WriteConcernError struct {
	Name    string
	Code    int
	Message string
	Details bson.Raw
}
func (wce WriteConcernError) Error() string {
	if wce.Name != "" {
		return fmt.Sprintf("(%v) %v", wce.Name, wce.Message)
	}
	return wce.Message
}
type WriteException struct {
	WriteConcernError *WriteConcernError
	WriteErrors WriteErrors
	Labels []string
}
func (mwe WriteException) Error() string {
	var buf bytes.Buffer
	fmt.Fprint(&buf, "multiple write errors: [")
	fmt.Fprintf(&buf, "{%s}, ", mwe.WriteErrors)
	fmt.Fprintf(&buf, "{%s}]", mwe.WriteConcernError)
	return buf.String()
}
func (mwe WriteException) HasErrorCode(code int) bool {
	if mwe.WriteConcernError != nil && mwe.WriteConcernError.Code == code {
		return true
	}
	for _, we := range mwe.WriteErrors {
		if we.Code == code {
			return true
		}
	}
	return false
}
func (mwe WriteException) HasErrorLabel(label string) bool {
	if mwe.Labels != nil {
		for _, l := range mwe.Labels {
			if l == label {
				return true
			}
		}
	}
	return false
}
func (mwe WriteException) HasErrorMessage(message string) bool {
	if mwe.WriteConcernError != nil && strings.Contains(mwe.WriteConcernError.Message, message) {
		return true
	}
	for _, we := range mwe.WriteErrors {
		if strings.Contains(we.Message, message) {
			return true
		}
	}
	return false
}
func (mwe WriteException) HasErrorCodeWithMessage(code int, message string) bool {
	if mwe.WriteConcernError != nil &&
		mwe.WriteConcernError.Code == code && strings.Contains(mwe.WriteConcernError.Message, message) {
		return true
	}
	for _, we := range mwe.WriteErrors {
		if we.Code == code && strings.Contains(we.Message, message) {
			return true
		}
	}
	return false
}
func (mwe WriteException) serverError() {}
func convertDriverWriteConcernError(wce *driver.WriteConcernError) *WriteConcernError {
	if wce == nil {
		return nil
	}
	return &WriteConcernError{
		Name:    wce.Name,
		Code:    int(wce.Code),
		Message: wce.Message,
		Details: bson.Raw(wce.Details),
	}
}
type BulkWriteError struct {
	WriteError             
	Request    WriteModel  
}
func (bwe BulkWriteError) Error() string {
	var buf bytes.Buffer
	fmt.Fprintf(&buf, "{%s}", bwe.WriteError)
	return buf.String()
}
type BulkWriteException struct {
	WriteConcernError *WriteConcernError
	WriteErrors []BulkWriteError
	Labels []string
}
func (bwe BulkWriteException) Error() string {
	var buf bytes.Buffer
	fmt.Fprint(&buf, "bulk write error: [")
	fmt.Fprintf(&buf, "{%s}, ", bwe.WriteErrors)
	fmt.Fprintf(&buf, "{%s}]", bwe.WriteConcernError)
	return buf.String()
}
func (bwe BulkWriteException) HasErrorCode(code int) bool {
	if bwe.WriteConcernError != nil && bwe.WriteConcernError.Code == code {
		return true
	}
	for _, we := range bwe.WriteErrors {
		if we.Code == code {
			return true
		}
	}
	return false
}
func (bwe BulkWriteException) HasErrorLabel(label string) bool {
	if bwe.Labels != nil {
		for _, l := range bwe.Labels {
			if l == label {
				return true
			}
		}
	}
	return false
}
func (bwe BulkWriteException) HasErrorMessage(message string) bool {
	if bwe.WriteConcernError != nil && strings.Contains(bwe.WriteConcernError.Message, message) {
		return true
	}
	for _, we := range bwe.WriteErrors {
		if strings.Contains(we.Message, message) {
			return true
		}
	}
	return false
}