Skip to content

Commit

Permalink
[custom-types: fix/suppress lint complaints]
Browse files Browse the repository at this point in the history
Suppressing `errname` for consistency with `wkbcommon` exception types;
suppressing `ireturn` because the concrete type returned depends on the
branch and thus no single concrete type specification is possible.
  • Loading branch information
wchargin committed Jul 1, 2024
1 parent bac1074 commit 06340f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 5 additions & 3 deletions pgxgeom.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type GeomScanner interface {
ScanGeom(v geom.T) error
}

// GeomValuer enables PostGIS geometry/geography values to be marshalled from
// GeomValuer enables PostGIS geometry/geography values to be marshaled from
// arbitrary Go types. For more context, see section "Extending Existing
// PostgreSQL Type Support" of the README for jackc/pgx/v5/pgtype.
type GeomValuer interface {
Expand All @@ -87,7 +87,7 @@ type GeomValuer interface {
// ErrUnexpectedType indicates that a PostGIS value did not meet the type
// constraints to be scanned into a particular Go value. For example, this
// occurs when attempting to scan a `geometry(point)` into a `*geom.Polygon`.
type ErrUnexpectedType struct {
type ErrUnexpectedType struct { //nolint: errname
Got any
Want any
}
Expand All @@ -99,7 +99,7 @@ func (e ErrUnexpectedType) Error() string {
// ErrUnsupportedType indicates that a given Go value could not be converted to
// a GeomScanner/GeomValuer. For example, this occurs if you attempt to scan
// into a `*bool`.
type ErrUnsupportedType struct {
type ErrUnsupportedType struct { //nolint: errname
Got any
}

Expand Down Expand Up @@ -146,6 +146,7 @@ func (sc concreteScanner[T]) ScanGeom(v geom.T) error {
return nil
}

//nolint:ireturn
func getGeomScanner(v any) (GeomScanner, error) {
switch v := v.(type) {
case GeomScanner:
Expand All @@ -171,6 +172,7 @@ func getGeomScanner(v any) (GeomScanner, error) {
}
}

//nolint:ireturn
func getGeomValuer(v any) (GeomValuer, error) {
switch v := v.(type) {
case GeomValuer:
Expand Down
11 changes: 6 additions & 5 deletions pgxgeom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ func TestCodecScanValuePolymorphic(t *testing.T) {

err = conn.QueryRow(ctx, query, pgx.QueryResultFormats{format}).Scan(&point)
assert.Error(t, err)
err = err.(pgx.ScanArgError).Err
assert.Equal(t, err.Error(), "pgxgeom: got *geom.Polygon, want *geom.Point")
var scanArgError pgx.ScanArgError
assert.True(t, errors.As(err, &scanArgError))
assert.Equal(t, scanArgError.Err.Error(), "pgxgeom: got *geom.Polygon, want *geom.Point")
})
}
})
Expand All @@ -172,12 +173,12 @@ type CustomPoint struct {
*geom.Point
}

var customPointScanError = errors.New("invalid target for CustomPoint")
var errCustomPointScan = errors.New("invalid target for CustomPoint")

func (c *CustomPoint) ScanGeom(v geom.T) error {
concrete, ok := v.(*geom.Point)
if !ok {
return customPointScanError
return errCustomPointScan
}
c.Point = concrete
return nil
Expand Down Expand Up @@ -221,7 +222,7 @@ func TestCodecScanValueCustom(t *testing.T) {

err = conn.QueryRow(ctx, polygonQuery, pgx.QueryResultFormats{format}).Scan(&point)
assert.Error(t, err)
assert.Equal(t, err, error(pgx.ScanArgError{Err: customPointScanError}))
assert.Equal(t, err, error(pgx.ScanArgError{Err: errCustomPointScan}))
})
}
})
Expand Down

0 comments on commit 06340f1

Please sign in to comment.