• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

go-sql-driver / mysql / 14310852047

07 Apr 2025 01:44PM CUT coverage: 82.857% (-0.1%) from 82.959%
14310852047

Pull #1681

github

shogo82148
README.md: update Go version requirement to 1.22 or higher
Pull Request #1681: add Go 1.24 to the test matrix

3248 of 3920 relevant lines covered (82.86%)

2441799.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.35
/errors.go
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 `Config.MaxAllowedPacket`")
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. Use mc.markBadConn(err) to do this.
36
        // See https://github.com/go-sql-driver/mysql/pull/302
37
        errBadConnNoWrite = errors.New("bad connection")
38
)
39

40
var defaultLogger = Logger(log.New(os.Stderr, "[mysql] ", log.Ldate|log.Ltime))
41

42
// Logger is used to log critical error messages.
43
type Logger interface {
44
        Print(v ...any)
45
}
46

47
// NopLogger is a nop implementation of the Logger interface.
48
type NopLogger struct{}
49

50
// Print implements Logger interface.
51
func (nl *NopLogger) Print(_ ...any) {}
×
52

53
// SetLogger is used to set the default logger for critical errors.
54
// The initial logger is os.Stderr.
55
func SetLogger(logger Logger) error {
224✔
56
        if logger == nil {
224✔
57
                return errors.New("logger is nil")
×
58
        }
×
59
        defaultLogger = logger
224✔
60
        return nil
224✔
61
}
62

63
// MySQLError is an error type which represents a single MySQL error
64
type MySQLError struct {
65
        Number   uint16
66
        SQLState [5]byte
67
        Message  string
68
}
69

70
func (me *MySQLError) Error() string {
131✔
71
        if me.SQLState != [5]byte{} {
163✔
72
                return fmt.Sprintf("Error %d (%s): %s", me.Number, me.SQLState, me.Message)
32✔
73
        }
32✔
74

75
        return fmt.Sprintf("Error %d: %s", me.Number, me.Message)
99✔
76
}
77

78
func (me *MySQLError) Is(err error) bool {
1,197✔
79
        if merr, ok := err.(*MySQLError); ok {
1,261✔
80
                return merr.Number == me.Number
64✔
81
        }
64✔
82
        return false
1,133✔
83
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc