diff options
author | 2021-08-12 21:03:24 +0200 | |
---|---|---|
committer | 2021-08-12 21:03:24 +0200 | |
commit | 98263a7de64269898a2f81207e38943b5c8e8653 (patch) | |
tree | 743c90f109a6c5d27832d1dcef2388d939f0f77a /vendor/github.com/go-pg/pg/v10/error.go | |
parent | Text duplication fix (#137) (diff) | |
download | gotosocial-98263a7de64269898a2f81207e38943b5c8e8653.tar.xz |
Grand test fixup (#138)
* start fixing up tests
* fix up tests + automate with drone
* fiddle with linting
* messing about with drone.yml
* some more fiddling
* hmmm
* add cache
* add vendor directory
* verbose
* ci updates
* update some little things
* update sig
Diffstat (limited to 'vendor/github.com/go-pg/pg/v10/error.go')
-rw-r--r-- | vendor/github.com/go-pg/pg/v10/error.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/vendor/github.com/go-pg/pg/v10/error.go b/vendor/github.com/go-pg/pg/v10/error.go new file mode 100644 index 000000000..d8113a010 --- /dev/null +++ b/vendor/github.com/go-pg/pg/v10/error.go @@ -0,0 +1,69 @@ +package pg + +import ( + "net" + + "github.com/go-pg/pg/v10/internal" +) + +// ErrNoRows is returned by QueryOne and ExecOne when query returned zero rows +// but at least one row is expected. +var ErrNoRows = internal.ErrNoRows + +// ErrMultiRows is returned by QueryOne and ExecOne when query returned +// multiple rows but exactly one row is expected. +var ErrMultiRows = internal.ErrMultiRows + +// Error represents an error returned by PostgreSQL server +// using PostgreSQL ErrorResponse protocol. +// +// https://www.postgresql.org/docs/10/static/protocol-message-formats.html +type Error interface { + error + + // Field returns a string value associated with an error field. + // + // https://www.postgresql.org/docs/10/static/protocol-error-fields.html + Field(field byte) string + + // IntegrityViolation reports whether an error is a part of + // Integrity Constraint Violation class of errors. + // + // https://www.postgresql.org/docs/10/static/errcodes-appendix.html + IntegrityViolation() bool +} + +var _ Error = (*internal.PGError)(nil) + +func isBadConn(err error, allowTimeout bool) bool { + if err == nil { + return false + } + if _, ok := err.(internal.Error); ok { + return false + } + if pgErr, ok := err.(Error); ok { + switch pgErr.Field('V') { + case "FATAL", "PANIC": + return true + } + switch pgErr.Field('C') { + case "25P02", // current transaction is aborted + "57014": // canceling statement due to user request + return true + } + return false + } + if allowTimeout { + if netErr, ok := err.(net.Error); ok && netErr.Timeout() { + return !netErr.Temporary() + } + } + return true +} + +//------------------------------------------------------------------------------ + +type timeoutError interface { + Timeout() bool +} |