Пример #1
0
func Test_ErrorCode(t *testing.T) {
	err1 := new(mysql.Error)
	err1.Code = 123
	err1.Msg = []byte("Test1")

	myT := new(assert.Tspy)
	ErrorCode(myT, err1, 1234)

	if !myT.Failed() {
		t.Fatal("Expected ErrorCode to fail.")
	}

	myT = new(assert.Tspy)
	ErrorCode(myT, err1, 123)

	if myT.Failed() {
		t.Fatal("Expected ErrorCode not to fail.")
	}

	err2 := errors.New("Test1")
	myT = new(assert.Tspy)
	ErrorCode(myT, err2, 1234)

	if !myT.Failed() {
		t.Fatal("Expected ErrorCode to fail.")
	}

	myT = new(assert.Tspy)
	ErrorCode(myT, nil, 1234)

	if !myT.Failed() {
		t.Fatal("Expected ErrorCode to fail.")
	}
}
Пример #2
0
// GetMySqlErorr helper function casts error to *mysql.Error.
// If err is not *mysql.Error it still returns *mysql.Error but
// with invalid (not used) MySQL error code 9999.
// Applicable only to github.com/ziutek/mymysql/mysql package.
func GetMySqlErorr(err error) *mysql.Error {
	var ok bool
	var mysqle *mysql.Error

	mysqle, ok = err.(*mysql.Error)

	if !ok {
		mysqle = new(mysql.Error)
		if err == nil {
			mysqle.Msg = []byte("")
		} else {
			mysqle.Msg = []byte(err.Error())
		}
		mysqle.Code = DUMMY_MYSQL_ERROR_CODE
	}
	return mysqle
}
Пример #3
0
func (my *Conn) getErrorPacket(pr *pktReader) {
	if my.Debug {
		log.Printf("[%2d ->] Error packet:", my.seq-1)
	}
	var err mysql.Error
	err.Code = readU16(pr)
	if readByte(pr) != '#' {
		panic(PKT_ERROR)
	}
	read(pr, 5)
	err.Msg = pr.readAll()
	pr.checkEof()

	if my.Debug {
		log.Printf(tab8s+"code=0x%x msg=\"%s\"", err.Code, err.Msg)
	}
	panic(&err)
}