1 Star 1 Fork 0

bigbase/pg

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
error.go 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
package pg
import (
"fmt"
"net"
)
var (
ErrSSLNotSupported = errorf("pg: SSL is not enabled on the server")
ErrNoRows = errorf("pg: no rows in result set")
ErrMultiRows = errorf("pg: multiple rows in result set")
errClosed = errorf("pg: database is closed")
errTxDone = errorf("pg: transaction has already been committed or rolled back")
errStmtClosed = errorf("pg: statement is closed")
errListenerClosed = errorf("pg: listener is closed")
)
var (
_ Error = &pgError{}
_ Error = &pgError{}
)
type Error interface {
Field(byte) string
}
type dbError struct {
s string
}
func errorf(s string, args ...interface{}) dbError {
return dbError{s: fmt.Sprintf(s, args...)}
}
func (err dbError) Error() string {
return err.s
}
type pgError struct {
c map[byte]string
}
func (err *pgError) Field(k byte) string {
return err.c[k]
}
func (err *pgError) Error() string {
return fmt.Sprintf(
"%s #%s %s: %s",
err.Field('S'), err.Field('C'), err.Field('M'), err.Field('D'),
)
}
type IntegrityError struct {
*pgError
}
func canRetry(e error) bool {
if e == nil {
return false
}
// 40001 - serialization_failure
if pgerr, ok := e.(Error); ok && pgerr.Field('C') != "40001" {
return false
}
if _, ok := e.(dbError); ok {
return false
}
if neterr, ok := e.(net.Error); ok && neterr.Timeout() {
return false
}
return true
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/bigbase/pg.git
git@gitee.com:bigbase/pg.git
bigbase
pg
pg
v3.3.10

搜索帮助