Skip to content

Commit

Permalink
server: redact some error code, part(2/3) (#20591) (#21891)
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
ti-srebot authored Jan 26, 2021
1 parent 1ddfaad commit 55a1f65
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
10 changes: 5 additions & 5 deletions errno/errname.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ var MySQLErrName = map[uint16]*mysql.ErrMessage{
ErrForeignServerDoesntExist: mysql.Message("The foreign server name you are trying to reference does not exist. Data source : %-.64s", nil),
ErrIllegalHaCreateOption: mysql.Message("Table storage engine '%-.64s' does not support the create option '%.64s'", nil),
ErrPartitionRequiresValues: mysql.Message("Syntax : %-.64s PARTITIONING requires definition of VALUES %-.64s for each partition", nil),
ErrPartitionWrongValues: mysql.Message("Only %-.64s PARTITIONING can use VALUES %-.64s in partition definition", nil),
ErrPartitionWrongValues: mysql.Message("Only %-.64s PARTITIONING can use VALUES %-.64s in partition definition", []int{1}),
ErrPartitionMaxvalue: mysql.Message("MAXVALUE can only be used in last partition definition", nil),
ErrPartitionSubpartition: mysql.Message("Subpartitions can only be hash partitions and by key", nil),
ErrPartitionSubpartMix: mysql.Message("Must define subpartitions on all partitions if on one partition", nil),
Expand All @@ -524,7 +524,7 @@ var MySQLErrName = map[uint16]*mysql.ErrMessage{
ErrCantCreateHandlerFile: mysql.Message("Failed to create specific handler file", nil),
ErrBlobFieldInPartFunc: mysql.Message("A BLOB field is not allowed in partition function", nil),
ErrUniqueKeyNeedAllFieldsInPf: mysql.Message("A %-.192s must include all columns in the table's partitioning function", nil),
ErrNoParts: mysql.Message("Number of %-.64s = 0 is not an allowed value", nil),
ErrNoParts: mysql.Message("Number of %-.64s = 0 is not an allowed value", []int{0}),
ErrPartitionMgmtOnNonpartitioned: mysql.Message("Partition management on a not partitioned table is not possible", nil),
ErrForeignKeyOnPartitioned: mysql.Message("Foreign key clause is not yet supported in conjunction with partitioning", nil),
ErrDropPartitionNonExistent: mysql.Message("Error in list of partitions to %-.64s", nil),
Expand All @@ -545,8 +545,8 @@ var MySQLErrName = map[uint16]*mysql.ErrMessage{
ErrPartState: mysql.Message("Partition state cannot be defined from CREATE/ALTER TABLE", nil),
ErrLimitedPartRange: mysql.Message("The %-.64s handler only supports 32 bit integers in VALUES", nil),
ErrPluginIsNotLoaded: mysql.Message("Plugin '%-.192s' is not loaded", nil),
ErrWrongValue: mysql.Message("Incorrect %-.32s value: '%-.128s'", nil),
ErrNoPartitionForGivenValue: mysql.Message("Table has no partition for value %-.64s", nil),
ErrWrongValue: mysql.Message("Incorrect %-.32s value: '%-.128s'", []int{1}),
ErrNoPartitionForGivenValue: mysql.Message("Table has no partition for value %-.64s", []int{0}),
ErrFilegroupOptionOnlyOnce: mysql.Message("It is not allowed to specify %s more than once", nil),
ErrCreateFilegroupFailed: mysql.Message("Failed to create %s", nil),
ErrDropFilegroupFailed: mysql.Message("Failed to drop %s", nil),
Expand Down Expand Up @@ -710,7 +710,7 @@ var MySQLErrName = map[uint16]*mysql.ErrMessage{
ErrSpatialMustHaveGeomCol: mysql.Message("A SPATIAL index may only contain a geometrical type column", nil),
ErrTooLongIndexComment: mysql.Message("Comment for index '%-.64s' is too long (max = %d)", nil),
ErrLockAborted: mysql.Message("Wait on a lock was aborted due to a pending exclusive lock", nil),
ErrDataOutOfRange: mysql.Message("%s value is out of range in '%s'", nil),
ErrDataOutOfRange: mysql.Message("%s value is out of range in '%s'", []int{1}),
ErrWrongSpvarTypeInLimit: mysql.Message("A variable of a non-integer based type in LIMIT clause", nil),
ErrBinlogUnsafeMultipleEnginesAndSelfLoggingEngine: mysql.Message("Mixing self-logging and non-self-logging engines in a statement is unsafe.", nil),
ErrBinlogUnsafeMixedStatement: mysql.Message("Statement accesses nontransactional table as well as transactional or temporary table, and writes to any of them.", nil),
Expand Down
26 changes: 22 additions & 4 deletions util/dbterror/terror_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package dbterror

import (
"fmt"
"strings"
"testing"

Expand All @@ -30,14 +31,31 @@ var _ = Suite(&testkSuite{})

type testkSuite struct{}

func genErrMsg(pattern string, a ...interface{}) string {
return fmt.Sprintf(pattern, a...)
}

func (s *testkSuite) TestErrorRedact(c *C) {
original := errors.RedactLogEnabled.Load()
errors.RedactLogEnabled.Store(true)
defer func() { errors.RedactLogEnabled.Store(original) }()

class := ErrClass{}
err := class.NewStd(errno.ErrDupEntry).GenWithStackByArgs("sensitive_data", "no_sensitive")
c.Assert(strings.Contains(err.Error(), "?"), IsTrue)
c.Assert(strings.Contains(err.Error(), "no_sensitive"), IsTrue)
c.Assert(strings.Contains(err.Error(), "sensitive_data"), IsFalse)

NoSensitiveValue := "no_sensitive"
SensitiveData := "sensitive_data"
QuestionMark := "?"

err := class.NewStd(errno.ErrDupEntry).GenWithStackByArgs(SensitiveData, NoSensitiveValue)
c.Assert(strings.Contains(err.Error(), genErrMsg(errno.MySQLErrName[errno.ErrDupEntry].Raw, QuestionMark, NoSensitiveValue)), IsTrue)
err = class.NewStd(errno.ErrPartitionWrongValues).GenWithStackByArgs(NoSensitiveValue, SensitiveData)
c.Assert(strings.Contains(err.Error(), genErrMsg(errno.MySQLErrName[errno.ErrPartitionWrongValues].Raw, NoSensitiveValue, QuestionMark)), IsTrue)
err = class.NewStd(errno.ErrNoParts).GenWithStackByArgs(SensitiveData)
c.Assert(strings.Contains(err.Error(), genErrMsg(errno.MySQLErrName[errno.ErrNoParts].Raw, QuestionMark)), IsTrue)
err = class.NewStd(errno.ErrWrongValue).GenWithStackByArgs(NoSensitiveValue, SensitiveData)
c.Assert(strings.Contains(err.Error(), genErrMsg(errno.MySQLErrName[errno.ErrWrongValue].Raw, NoSensitiveValue, QuestionMark)), IsTrue)
err = class.NewStd(errno.ErrNoPartitionForGivenValue).GenWithStackByArgs(SensitiveData)
c.Assert(strings.Contains(err.Error(), genErrMsg(errno.MySQLErrName[errno.ErrNoPartitionForGivenValue].Raw, QuestionMark)), IsTrue)
err = class.NewStd(errno.ErrDataOutOfRange).GenWithStackByArgs(NoSensitiveValue, SensitiveData)
c.Assert(strings.Contains(err.Error(), genErrMsg(errno.MySQLErrName[errno.ErrDataOutOfRange].Raw, NoSensitiveValue, QuestionMark)), IsTrue)
}

0 comments on commit 55a1f65

Please sign in to comment.