Skip to content

Commit

Permalink
executor: fix the error message when granting to a non-exist user (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored and zz-jason committed May 5, 2019
1 parent bbe1e69 commit 62d37a8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions executor/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
ErrBuildExecutor = terror.ClassExecutor.New(codeErrBuildExec, "Failed to build executor")
ErrBatchInsertFail = terror.ClassExecutor.New(codeBatchInsertFail, "Batch insert failed, please clean the table and try again.")

ErrCantCreateUserWithGrant = terror.ClassExecutor.New(mysql.ErrCantCreateUserWithGrant, mysql.MySQLErrName[mysql.ErrCantCreateUserWithGrant])
ErrPasswordNoMatch = terror.ClassExecutor.New(mysql.ErrPasswordNoMatch, mysql.MySQLErrName[mysql.ErrPasswordNoMatch])
ErrCannotUser = terror.ClassExecutor.New(mysql.ErrCannotUser, mysql.MySQLErrName[mysql.ErrCannotUser])
ErrPasswordFormat = terror.ClassExecutor.New(mysql.ErrPasswordFormat, mysql.MySQLErrName[mysql.ErrPasswordFormat])
Expand Down
2 changes: 1 addition & 1 deletion executor/grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (e *GrantExec) Next(ctx context.Context, req *chunk.RecordBatch) error {
return err
}
if !exists && e.ctx.GetSessionVars().SQLMode.HasNoAutoCreateUserMode() {
return ErrPasswordNoMatch
return ErrCantCreateUserWithGrant
} else if !exists {
pwd, ok := user.EncodedPassword()
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion executor/grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (s *testSuite3) TestNoAutoCreateUser(c *C) {
tk.MustExec(`SET sql_mode='NO_AUTO_CREATE_USER'`)
_, err := tk.Exec(`GRANT ALL PRIVILEGES ON *.* to 'test'@'%' IDENTIFIED BY 'xxx'`)
c.Check(err, NotNil)
c.Assert(terror.ErrorEqual(err, executor.ErrPasswordNoMatch), IsTrue)
c.Assert(terror.ErrorEqual(err, executor.ErrCantCreateUserWithGrant), IsTrue)
}

func (s *testSuite3) TestCreateUserWhenGrant(c *C) {
Expand Down

0 comments on commit 62d37a8

Please sign in to comment.