Skip to content

Commit a059889

Browse files
committedJan 19, 2016
reformat errors
1 parent ca130be commit a059889

File tree

5 files changed

+43
-43
lines changed

5 files changed

+43
-43
lines changed
 

‎dsn.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import (
1919
)
2020

2121
var (
22-
errInvalidDSNUnescaped = errors.New("Invalid DSN: Did you forget to escape a param value?")
23-
errInvalidDSNAddr = errors.New("Invalid DSN: Network Address not terminated (missing closing brace)")
24-
errInvalidDSNNoSlash = errors.New("Invalid DSN: Missing the slash separating the database name")
25-
errInvalidDSNUnsafeCollation = errors.New("Invalid DSN: interpolateParams can be used with ascii, latin1, utf8 and utf8mb4 charset")
22+
errInvalidDSNUnescaped = errors.New("invalid DSN: did you forget to escape a param value?")
23+
errInvalidDSNAddr = errors.New("invalid DSN: network address not terminated (missing closing brace)")
24+
errInvalidDSNNoSlash = errors.New("invalid DSN: missing the slash separating the database name")
25+
errInvalidDSNUnsafeCollation = errors.New("invalid DSN: interpolateParams can not be used with unsafe collations")
2626
)
2727

2828
// Config is a configuration parsed from a DSN string
@@ -141,7 +141,7 @@ func ParseDSN(dsn string) (cfg *Config, err error) {
141141
case "unix":
142142
cfg.Addr = "/tmp/mysql.sock"
143143
default:
144-
return nil, errors.New("Default addr for network '" + cfg.Net + "' unknown")
144+
return nil, errors.New("default addr for network '" + cfg.Net + "' unknown")
145145
}
146146

147147
}
@@ -166,31 +166,31 @@ func parseDSNParams(cfg *Config, params string) (err error) {
166166
var isBool bool
167167
cfg.AllowAllFiles, isBool = readBool(value)
168168
if !isBool {
169-
return fmt.Errorf("Invalid Bool value: %s", value)
169+
return errors.New("invalid bool value: " + value)
170170
}
171171

172172
// Use cleartext authentication mode (MySQL 5.5.10+)
173173
case "allowCleartextPasswords":
174174
var isBool bool
175175
cfg.AllowCleartextPasswords, isBool = readBool(value)
176176
if !isBool {
177-
return fmt.Errorf("Invalid Bool value: %s", value)
177+
return errors.New("invalid bool value: " + value)
178178
}
179179

180180
// Use old authentication mode (pre MySQL 4.1)
181181
case "allowOldPasswords":
182182
var isBool bool
183183
cfg.AllowOldPasswords, isBool = readBool(value)
184184
if !isBool {
185-
return fmt.Errorf("Invalid Bool value: %s", value)
185+
return errors.New("invalid bool value: " + value)
186186
}
187187

188188
// Switch "rowsAffected" mode
189189
case "clientFoundRows":
190190
var isBool bool
191191
cfg.ClientFoundRows, isBool = readBool(value)
192192
if !isBool {
193-
return fmt.Errorf("Invalid Bool value: %s", value)
193+
return errors.New("invalid bool value: " + value)
194194
}
195195

196196
// Collation
@@ -210,19 +210,19 @@ func parseDSNParams(cfg *Config, params string) (err error) {
210210
var isBool bool
211211
cfg.ColumnsWithAlias, isBool = readBool(value)
212212
if !isBool {
213-
return fmt.Errorf("Invalid Bool value: %s", value)
213+
return errors.New("invalid bool value: " + value)
214214
}
215215

216216
// Compression
217217
case "compress":
218-
return errors.New("Compression not implemented yet")
218+
return errors.New("compression not implemented yet")
219219

220220
// Enable client side placeholder substitution
221221
case "interpolateParams":
222222
var isBool bool
223223
cfg.InterpolateParams, isBool = readBool(value)
224224
if !isBool {
225-
return fmt.Errorf("Invalid Bool value: %s", value)
225+
return errors.New("invalid bool value: " + value)
226226
}
227227

228228
// Time Location
@@ -240,7 +240,7 @@ func parseDSNParams(cfg *Config, params string) (err error) {
240240
var isBool bool
241241
cfg.ParseTime, isBool = readBool(value)
242242
if !isBool {
243-
return errors.New("Invalid Bool value: " + value)
243+
return errors.New("invalid bool value: " + value)
244244
}
245245

246246
// I/O read Timeout
@@ -255,7 +255,7 @@ func parseDSNParams(cfg *Config, params string) (err error) {
255255
var isBool bool
256256
cfg.Strict, isBool = readBool(value)
257257
if !isBool {
258-
return errors.New("Invalid Bool value: " + value)
258+
return errors.New("invalid bool value: " + value)
259259
}
260260

261261
// Dial Timeout
@@ -273,7 +273,7 @@ func parseDSNParams(cfg *Config, params string) (err error) {
273273
cfg.TLS = &tls.Config{}
274274
}
275275
} else if value, err := url.QueryUnescape(value); err != nil {
276-
return fmt.Errorf("Invalid value for tls config name: %v", err)
276+
return fmt.Errorf("invalid value for TLS config name: %v", err)
277277
} else {
278278
if strings.ToLower(value) == "skip-verify" {
279279
cfg.TLS = &tls.Config{InsecureSkipVerify: true}
@@ -287,7 +287,7 @@ func parseDSNParams(cfg *Config, params string) (err error) {
287287

288288
cfg.TLS = tlsConfig
289289
} else {
290-
return fmt.Errorf("Invalid value / unknown config name: %s", value)
290+
return errors.New("invalid value / unknown config name: " + value)
291291
}
292292
}
293293

‎errors.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ import (
1919

2020
// Various errors the driver might return. Can change between driver versions.
2121
var (
22-
ErrInvalidConn = errors.New("Invalid Connection")
23-
ErrMalformPkt = errors.New("Malformed Packet")
24-
ErrNoTLS = errors.New("TLS encryption requested but server does not support TLS")
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-
ErrCleartextPassword = errors.New("This user requires clear text authentication. If you still want to use it, please add 'allowCleartextPasswords=1' to your DSN.")
27-
ErrUnknownPlugin = errors.New("The authentication plugin is not supported.")
28-
ErrOldProtocol = errors.New("MySQL-Server does not support required Protocol 41+")
29-
ErrPktSync = errors.New("Commands out of sync. You can't run this command now")
30-
ErrPktSyncMul = errors.New("Commands out of sync. Did you run multiple statements at once?")
31-
ErrPktTooLarge = errors.New("Packet for query is too large. You can change this value on the server by adjusting the 'max_allowed_packet' variable.")
32-
ErrBusyBuffer = errors.New("Busy buffer")
22+
ErrInvalidConn = errors.New("invalid connection")
23+
ErrMalformPkt = errors.New("malformed packet")
24+
ErrNoTLS = errors.New("TLS requested but server does not support TLS")
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+
ErrCleartextPassword = errors.New("this user requires clear text authentication. If you still want to use it, please add 'allowCleartextPasswords=1' to your DSN")
27+
ErrUnknownPlugin = errors.New("this authentication plugin is not supported")
28+
ErrOldProtocol = errors.New("MySQL server does not support required protocol 41+")
29+
ErrPktSync = errors.New("commands out of sync. You can't run this command now")
30+
ErrPktSyncMul = errors.New("commands out of sync. Did you run multiple statements at once?")
31+
ErrPktTooLarge = errors.New("packet for query is too large. Try adjusting the 'max_allowed_packet' variable on the server")
32+
ErrBusyBuffer = errors.New("busy buffer")
3333
)
3434

35-
var errLog = Logger(log.New(os.Stderr, "[MySQL] ", log.Ldate|log.Ltime|log.Lshortfile))
35+
var errLog = Logger(log.New(os.Stderr, "[mysql] ", log.Ldate|log.Ltime|log.Lshortfile))
3636

3737
// Logger is used to log critical error messages.
3838
type Logger interface {
@@ -56,7 +56,7 @@ type MySQLError struct {
5656
}
5757

5858
func (me *MySQLError) Error() string {
59-
return fmt.Sprintf("Error %d: %s", me.Number, me.Message)
59+
return fmt.Sprintf("error %d: %s", me.Number, me.Message)
6060
}
6161

6262
// MySQLWarnings is an error type which represents a group of one or more MySQL

‎infile.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ func (mc *mysqlConn) handleInFileRequest(name string) (err error) {
139139
} else if fileSize <= mc.maxPacketAllowed {
140140
data = make([]byte, 4+mc.maxWriteSize)
141141
} else {
142-
err = fmt.Errorf("Local File '%s' too large: Size: %d, Max: %d", name, fileSize, mc.maxPacketAllowed)
142+
err = fmt.Errorf("local file '%s' too large: size: %d, max: %d", name, fileSize, mc.maxPacketAllowed)
143143
}
144144
}
145145
}
146146
} else {
147-
err = fmt.Errorf("Local File '%s' is not registered. Use the DSN parameter 'allowAllFiles=true' to allow all files", name)
147+
err = fmt.Errorf("local file '%s' is not registered", name)
148148
}
149149
}
150150

‎packets.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (mc *mysqlConn) readInitPacket() ([]byte, error) {
145145
// protocol version [1 byte]
146146
if data[0] < minProtocolVersion {
147147
return nil, fmt.Errorf(
148-
"Unsupported MySQL Protocol Version %d. Protocol Version %d or higher is required",
148+
"unsupported protocol version %d. Version %d or higher is required",
149149
data[0],
150150
minProtocolVersion,
151151
)
@@ -563,7 +563,7 @@ func (mc *mysqlConn) readColumns(count int) ([]mysqlField, error) {
563563
if i == count {
564564
return columns, nil
565565
}
566-
return nil, fmt.Errorf("ColumnsCount mismatch n:%d len:%d", count, len(columns))
566+
return nil, fmt.Errorf("columns count mismatch n:%d len:%d", count, len(columns))
567567
}
568568

569569
// Catalog
@@ -809,7 +809,7 @@ func (stmt *mysqlStmt) writeCommandLongData(paramID int, arg []byte) error {
809809
func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
810810
if len(args) != stmt.paramCount {
811811
return fmt.Errorf(
812-
"Arguments count mismatch (Got: %d Has: %d)",
812+
"arguments count mismatch (got: %d; has: %d)",
813813
len(args),
814814
stmt.paramCount,
815815
)
@@ -995,7 +995,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
995995
paramValues = append(paramValues, val...)
996996

997997
default:
998-
return fmt.Errorf("Can't convert type: %T", arg)
998+
return fmt.Errorf("can not convert type: %T", arg)
999999
}
10001000
}
10011001

@@ -1143,7 +1143,7 @@ func (rows *binaryRows) readRow(dest []driver.Value) error {
11431143
dstlen = 8 + 1 + decimals
11441144
default:
11451145
return fmt.Errorf(
1146-
"MySQL protocol error, illegal decimals value %d",
1146+
"protocol error, illegal decimals value %d",
11471147
rows.columns[i].decimals,
11481148
)
11491149
}
@@ -1162,7 +1162,7 @@ func (rows *binaryRows) readRow(dest []driver.Value) error {
11621162
dstlen = 19 + 1 + decimals
11631163
default:
11641164
return fmt.Errorf(
1165-
"MySQL protocol error, illegal decimals value %d",
1165+
"protocol error, illegal decimals value %d",
11661166
rows.columns[i].decimals,
11671167
)
11681168
}
@@ -1179,7 +1179,7 @@ func (rows *binaryRows) readRow(dest []driver.Value) error {
11791179

11801180
// Please report if this happens!
11811181
default:
1182-
return fmt.Errorf("Unknown FieldType %d", rows.columns[i].fieldType)
1182+
return fmt.Errorf("unknown field type %d", rows.columns[i].fieldType)
11831183
}
11841184
}
11851185

‎utils.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var (
4848
//
4949
func RegisterTLSConfig(key string, config *tls.Config) error {
5050
if _, isBool := readBool(key); isBool || strings.ToLower(key) == "skip-verify" {
51-
return fmt.Errorf("Key '%s' is reserved", key)
51+
return fmt.Errorf("key '%s' is reserved", key)
5252
}
5353

5454
if tlsConfigRegister == nil {
@@ -260,7 +260,7 @@ func parseDateTime(str string, loc *time.Location) (t time.Time, err error) {
260260
}
261261
t, err = time.Parse(timeFormat[:len(str)], str)
262262
default:
263-
err = fmt.Errorf("Invalid Time-String: %s", str)
263+
err = fmt.Errorf("invalid time string: %s", str)
264264
return
265265
}
266266

@@ -309,7 +309,7 @@ func parseBinaryDateTime(num uint64, data []byte, loc *time.Location) (driver.Va
309309
loc,
310310
), nil
311311
}
312-
return nil, fmt.Errorf("Invalid DATETIME-packet length %d", num)
312+
return nil, fmt.Errorf("invalid DATETIME packet length %d", num)
313313
}
314314

315315
// zeroDateTime is used in formatBinaryDateTime to avoid an allocation
@@ -344,7 +344,7 @@ func formatBinaryDateTime(src []byte, length uint8, justTime bool) (driver.Value
344344
switch len(src) {
345345
case 8, 12:
346346
default:
347-
return nil, fmt.Errorf("Invalid TIME-packet length %d", len(src))
347+
return nil, fmt.Errorf("invalid TIME packet length %d", len(src))
348348
}
349349
// +2 to enable negative time and 100+ hours
350350
dst = make([]byte, 0, length+2)
@@ -378,7 +378,7 @@ func formatBinaryDateTime(src []byte, length uint8, justTime bool) (driver.Value
378378
if length > 10 {
379379
t += "TIME"
380380
}
381-
return nil, fmt.Errorf("illegal %s-packet length %d", t, len(src))
381+
return nil, fmt.Errorf("illegal %s packet length %d", t, len(src))
382382
}
383383
dst = make([]byte, 0, length)
384384
// start with the date

0 commit comments

Comments
 (0)
Please sign in to comment.