pgstatus

package module
v0.0.0-...-aac2ed3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2021 License: MIT Imports: 5 Imported by: 0

README

pgstatus-go

Postgres error to gRPC status.

Supports any error implementing a SQLState() string method that:

  1. Returns a postgres error code.
  2. Isn't already a gRPC *status.Status pointer.
  3. Doesn't implement a GRPCStatus() *grpc.Status.

Drivers

github.com/jackc/pgx

Supported as of github.com/jackc/pgx/v4. YMMV if you are using older version that don't use github.com/jackc/pgconn as I don't know the history of the SQLState() string interface in the driver.

github.com/lib/pq

Unsupported.

The pq package provides no usable interface. Casting to a *pq.Error and providing a SQLState() string is currently an exercise left to the reader.

github.com/go-pg/pg

Unsupported.

License

MIT

Documentation

Overview

Package pgstatus converts postgres errors to gRPC statuses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Code

func Code(err error) codes.Code

Code converts a database error into a gRPC codes.Code.

Postgres: https://www.postgresql.org/docs/current/static/errcodes-appendix.html GRPC: https://godoc.org/google.golang.org/grpc/codes

func ConditionName

func ConditionName(err error) (string, bool)

ConditionName for SQLStatus() interface error code.

func Convert

func Convert(err error) *status.Status

Convert is a convenience function which removes the need to handle the boolean return value from FromError.

func FromError

func FromError(err error) (*status.Status, bool)

FromError returns a gRPC status.Status representing an err if it was produced from status package, has a method `GRPCStatus() *status.Status` or has a method SQLState interface returning a postgres error code. Otherwise, ok is false and a Status is returned with codes.Unknown and the original error message.

Types

type SQLState

type SQLState interface {
	SQLState() string
}

SQLState error code interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL