Skip to content

Commit

Permalink
*: cleanup error code (pingcap#13874)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackysp authored and sre-bot committed Dec 3, 2019
1 parent dcbb5a1 commit 826e1d7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 31 deletions.
2 changes: 1 addition & 1 deletion meta/autoid/autoid.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func NewAllocator(store kv.Storage, dbID int64, isUnsigned bool) Allocator {
}
}

//codeInvalidTableID is the code of autoid error.
// codeInvalidTableID is the code of autoid error.
const codeInvalidTableID terror.ErrCode = 1

var localSchemaID = int64(math.MaxInt64)
Expand Down
8 changes: 3 additions & 5 deletions privilege/privileges/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@ import (

// privilege error codes.
const (
codeInvalidPrivilegeType terror.ErrCode = 1
codeInvalidUserNameFormat = 2
codeErrNonexistingGrant = mysql.ErrNonexistingGrant
codeInvalidPrivilegeType terror.ErrCode = 1
)

var (
errInvalidPrivilegeType = terror.ClassPrivilege.New(codeInvalidPrivilegeType, "unknown privilege type %s")
errNonexistingGrant = terror.ClassPrivilege.New(codeErrNonexistingGrant, mysql.MySQLErrName[mysql.ErrNonexistingGrant])
errNonexistingGrant = terror.ClassPrivilege.New(mysql.ErrNonexistingGrant, mysql.MySQLErrName[mysql.ErrNonexistingGrant])
)

func init() {
privilegeMySQLErrCodes := map[terror.ErrCode]uint16{
codeErrNonexistingGrant: mysql.ErrNonexistingGrant,
mysql.ErrNonexistingGrant: mysql.ErrNonexistingGrant,
}
terror.ErrClassToMySQLCodes[terror.ClassPrivilege] = privilegeMySQLErrCodes
}
20 changes: 7 additions & 13 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ var (
errUnknownFieldType = terror.ClassServer.New(codeUnknownFieldType, "unknown field type")
errInvalidSequence = terror.ClassServer.New(codeInvalidSequence, "invalid sequence")
errInvalidType = terror.ClassServer.New(codeInvalidType, "invalid type")
errNotAllowedCommand = terror.ClassServer.New(codeNotAllowedCommand, "the used command is not allowed with this TiDB version")
errAccessDenied = terror.ClassServer.New(codeAccessDenied, mysql.MySQLErrName[mysql.ErrAccessDenied])
errNotAllowedCommand = terror.ClassServer.New(mysql.ErrNotAllowedCommand, mysql.MySQLErrName[mysql.ErrNotAllowedCommand])
errAccessDenied = terror.ClassServer.New(mysql.ErrAccessDenied, mysql.MySQLErrName[mysql.ErrAccessDenied])
)

// DefaultCapability is the capability of the server when it is created using the default configuration.
Expand Down Expand Up @@ -617,21 +617,15 @@ func (s *Server) kickIdleConnection() {

// Server error codes.
const (
codeUnknownFieldType = 1
codeInvalidPayloadLen = 2
codeInvalidSequence = 3
codeInvalidType = 4

codeNotAllowedCommand = 1148
codeAccessDenied = mysql.ErrAccessDenied
codeMaxExecTimeExceeded = mysql.ErrMaxExecTimeExceeded
codeUnknownFieldType = 1
codeInvalidSequence = 3
codeInvalidType = 4
)

func init() {
serverMySQLErrCodes := map[terror.ErrCode]uint16{
codeNotAllowedCommand: mysql.ErrNotAllowedCommand,
codeAccessDenied: mysql.ErrAccessDenied,
codeMaxExecTimeExceeded: mysql.ErrMaxExecTimeExceeded,
mysql.ErrNotAllowedCommand: mysql.ErrNotAllowedCommand,
mysql.ErrAccessDenied: mysql.ErrAccessDenied,
}
terror.ErrClassToMySQLCodes[terror.ClassServer] = serverMySQLErrCodes
}
9 changes: 2 additions & 7 deletions session/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,17 +367,12 @@ func ResultSetToStringSlice(ctx context.Context, s Session, rs sqlexec.RecordSet

// Session errors.
var (
ErrForUpdateCantRetry = terror.ClassSession.New(codeForUpdateCantRetry,
mysql.MySQLErrName[mysql.ErrForUpdateCantRetry])
)

const (
codeForUpdateCantRetry terror.ErrCode = mysql.ErrForUpdateCantRetry
ErrForUpdateCantRetry = terror.ClassSession.New(mysql.ErrForUpdateCantRetry, mysql.MySQLErrName[mysql.ErrForUpdateCantRetry])
)

func init() {
sessionMySQLErrCodes := map[terror.ErrCode]uint16{
codeForUpdateCantRetry: mysql.ErrForUpdateCantRetry,
mysql.ErrForUpdateCantRetry: mysql.ErrForUpdateCantRetry,
}
terror.ErrClassToMySQLCodes[terror.ClassSession] = sessionMySQLErrCodes
}
8 changes: 3 additions & 5 deletions structure/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ import (

// structure error codes.
const (
codeInvalidHashKeyFlag terror.ErrCode = 1
codeInvalidHashKeyPrefix terror.ErrCode = 2
codeInvalidListIndex terror.ErrCode = 3
codeInvalidListMetaData terror.ErrCode = 4
codeWriteOnSnapshot terror.ErrCode = 5
codeInvalidHashKeyFlag terror.ErrCode = 1
codeInvalidListMetaData terror.ErrCode = 4
codeWriteOnSnapshot terror.ErrCode = 5
)

var (
Expand Down

0 comments on commit 826e1d7

Please sign in to comment.