github.com/hellobchain/third_party@v0.0.0-20230331131523-deb0478a2e52/go-sql-driver/mysql/errors.go (about)

     1  // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
     2  //
     3  // Copyright 2013 The Go-MySQL-Driver Authors. All rights reserved.
     4  //
     5  // This Source Code Form is subject to the terms of the Mozilla Public
     6  // License, v. 2.0. If a copy of the MPL was not distributed with this file,
     7  // You can obtain one at http://mozilla.org/MPL/2.0/.
     8  
     9  package mysql
    10  
    11  import (
    12  	"errors"
    13  	"fmt"
    14  	"log"
    15  	"os"
    16  )
    17  
    18  // Various errors the driver might return. Can change between driver versions.
    19  var (
    20  	ErrInvalidConn       = errors.New("invalid connection")
    21  	ErrMalformPkt        = errors.New("malformed packet")
    22  	ErrNoTLS             = errors.New("TLS requested but server does not support TLS")
    23  	ErrCleartextPassword = errors.New("this user requires clear text authentication. If you still want to use it, please add 'allowCleartextPasswords=1' to your DSN")
    24  	ErrNativePassword    = errors.New("this user requires mysql native password authentication.")
    25  	ErrOldPassword       = errors.New("this user requires old password authentication. If you still want to use it, please add 'allowOldPasswords=1' to your DSN. See also https://github.com/go-sql-driver/mysql/wiki/old_passwords")
    26  	ErrUnknownPlugin     = errors.New("this authentication plugin is not supported")
    27  	ErrOldProtocol       = errors.New("MySQL server does not support required protocol 41+")
    28  	ErrPktSync           = errors.New("commands out of sync. You can't run this command now")
    29  	ErrPktSyncMul        = errors.New("commands out of sync. Did you run multiple statements at once?")
    30  	ErrPktTooLarge       = errors.New("packet for query is too large. Try adjusting the 'max_allowed_packet' variable on the server")
    31  	ErrBusyBuffer        = errors.New("busy buffer")
    32  
    33  	// errBadConnNoWrite is used for connection errors where nothing was sent to the database yet.
    34  	// If this happens first in a function starting a database interaction, it should be replaced by driver.ErrBadConn
    35  	// to trigger a resend.
    36  	// See https://github.com/go-sql-driver/mysql/pull/302
    37  	errBadConnNoWrite = errors.New("bad connection")
    38  )
    39  
    40  var errLog = Logger(log.New(os.Stderr, "[mysql] ", log.Ldate|log.Ltime|log.Lshortfile))
    41  
    42  // Logger is used to log critical error messages.
    43  type Logger interface {
    44  	Print(v ...interface{})
    45  }
    46  
    47  // SetLogger is used to set the logger for critical errors.
    48  // The initial logger is os.Stderr.
    49  func SetLogger(logger Logger) error {
    50  	if logger == nil {
    51  		return errors.New("logger is nil")
    52  	}
    53  	errLog = logger
    54  	return nil
    55  }
    56  
    57  // MySQLError is an error type which represents a single MySQL error
    58  type MySQLError struct {
    59  	Number  uint16
    60  	Message string
    61  }
    62  
    63  func (me *MySQLError) Error() string {
    64  	return fmt.Sprintf("Error %d: %s", me.Number, me.Message)
    65  }