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

go-sql-driver / mysql / 8308409534

16 Mar 2024 02:23PM UTC coverage: 82.055%. Remained the same
8308409534

push

github

web-flow
replace interface{} with any (#1561)

2 of 3 new or added lines in 3 files covered. (66.67%)

3114 of 3795 relevant lines covered (82.06%)

1291904.48 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.
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|log.Lshortfile))
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.
NEW
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 {
150✔
56
        if logger == nil {
150✔
57
                return errors.New("logger is nil")
×
58
        }
×
59
        defaultLogger = logger
150✔
60
        return nil
150✔
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 {
42✔
71
        if me.SQLState != [5]byte{} {
72✔
72
                return fmt.Sprintf("Error %d (%s): %s", me.Number, me.SQLState, me.Message)
30✔
73
        }
30✔
74

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

78
func (me *MySQLError) Is(err error) bool {
798✔
79
        if merr, ok := err.(*MySQLError); ok {
858✔
80
                return merr.Number == me.Number
60✔
81
        }
60✔
82
        return false
738✔
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

© 2026 Coveralls, Inc