github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/geo/errors.go (about) 1 // Copyright 2020 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package geo 12 13 import ( 14 "fmt" 15 16 "github.com/cockroachdb/errors" 17 ) 18 19 // NewMismatchingSRIDsError returns the error message for SRIDs of GeospatialTypes 20 // a and b being a mismatch. 21 func NewMismatchingSRIDsError(a GeospatialType, b GeospatialType) error { 22 return errors.Newf( 23 "operation on mixed SRIDs forbidden: (%s, %d) != (%s, %d)", 24 a.Shape(), 25 a.SRID(), 26 b.Shape(), 27 b.SRID(), 28 ) 29 } 30 31 // EmptyGeometryError is an error that is returned when the Geometry or any 32 // parts of its subgeometries are empty. 33 type EmptyGeometryError struct { 34 cause error 35 } 36 37 var _ error = (*EmptyGeometryError)(nil) 38 var _ errors.SafeDetailer = (*EmptyGeometryError)(nil) 39 var _ fmt.Formatter = (*EmptyGeometryError)(nil) 40 var _ errors.Formatter = (*EmptyGeometryError)(nil) 41 42 // Error implements the error interface. 43 func (w *EmptyGeometryError) Error() string { return w.cause.Error() } 44 45 // Cause implements the errors.SafeDetailer interface. 46 func (w *EmptyGeometryError) Cause() error { return w.cause } 47 48 // Unwrap implements the SafeDetailer interface. 49 func (w *EmptyGeometryError) Unwrap() error { return w.cause } 50 51 // SafeDetails implements the SafeDetailer interface. 52 func (w *EmptyGeometryError) SafeDetails() []string { return []string{w.cause.Error()} } 53 54 // Format implements the errors.Formatter interface. 55 func (w *EmptyGeometryError) Format(s fmt.State, verb rune) { errors.FormatError(w, s, verb) } 56 57 // FormatError implements the errors.Formatter interface. 58 func (w *EmptyGeometryError) FormatError(p errors.Printer) (next error) { return w.cause } 59 60 // IsEmptyGeometryError returns true if the error is of type EmptyGeometryError. 61 func IsEmptyGeometryError(err error) bool { 62 return errors.HasType(err, &EmptyGeometryError{}) 63 } 64 65 // NewEmptyGeometryError returns an error indicating an empty geometry has been found. 66 func NewEmptyGeometryError() *EmptyGeometryError { 67 return &EmptyGeometryError{cause: errors.Newf("empty shape found")} 68 }