renamed "ScanErrorComplainer" to "ScanError"

master
Charles Iliya Krempeaux 2019-06-20 21:28:51 -07:00
parent 4b488c27a3
commit a88f1f8eeb
2 changed files with 16 additions and 23 deletions

View File

@ -1,31 +1,27 @@
package pathmatch package pathmatch
import ( import (
"fmt" "fmt"
) )
type ScanError interface {
type ScanErrorComplainer interface {
InternalErrorComplainer InternalErrorComplainer
ScanErrorComplainer() ScanError()
WrappedError() error WrappedError() error
} }
// internalScanError is the only underlying implementation that fits the
// internalScanErrorComplainer is the only underlying implementation that fits the // ScanError interface, in this library.
// ScanErrorComplainer interface, in this library. type internalScanError struct {
type internalScanErrorComplainer struct {
wrappedError error wrappedError error
argumentIndex int argumentIndex int
argumentType string argumentType string
} }
// newScanError creates a new internalScanError (struct) and
// newScanErrorComplainer creates a new internalScanErrorComplainer (struct) and // returns it as a ScanError (interface).
// returns it as a ScanErrorComplainer (interface). func newScanError(wrappedError error, argumentIndex int, argumentType string) ScanError {
func newScanErrorComplainer(wrappedError error, argumentIndex int, argumentType string) ScanErrorComplainer { err := internalScanError{
err := internalScanErrorComplainer{
wrappedError:wrappedError, wrappedError:wrappedError,
argumentIndex:argumentIndex, argumentIndex:argumentIndex,
argumentType:argumentType, argumentType:argumentType,
@ -34,28 +30,25 @@ func newScanErrorComplainer(wrappedError error, argumentIndex int, argumentType
return &err return &err
} }
// Error method is necessary to satisfy the 'error' interface (and the // Error method is necessary to satisfy the 'error' interface (and the
// ScanErrorComplainer interface). // ScanError interface).
func (err *internalScanErrorComplainer) Error() string { func (err *internalScanError) Error() string {
s := fmt.Sprintf("Internal Error: Received scan error for argument #%d (%s): %q", err.argumentIndex, err.argumentType, err.wrappedError.Error()) s := fmt.Sprintf("Internal Error: Received scan error for argument #%d (%s): %q", err.argumentIndex, err.argumentType, err.wrappedError.Error())
return s return s
} }
// InternalErrorComplainer method is necessary to satisfy the 'InternalErrorComplainer' interface. // InternalErrorComplainer method is necessary to satisfy the 'InternalErrorComplainer' interface.
// It exists to make this error type detectable in a Go type-switch. // It exists to make this error type detectable in a Go type-switch.
func (err *internalScanErrorComplainer) InternalErrorComplainer() { func (err *internalScanError) InternalErrorComplainer() {
// Nothing here. // Nothing here.
} }
// ScanError method is necessary to satisfy the 'ScanError' interface.
// ScanErrorComplainer method is necessary to satisfy the 'ScanErrorComplainer' interface.
// It exists to make this error type detectable in a Go type-switch. // It exists to make this error type detectable in a Go type-switch.
func (err *internalScanErrorComplainer) ScanErrorComplainer() { func (err *internalScanError) ScanError() {
// Nothing here. // Nothing here.
} }
func (err *internalScanErrorComplainer) WrappedError() error { func (err *internalScanError) WrappedError() error {
return err.wrappedError return err.wrappedError
} }

2
set.go
View File

@ -25,7 +25,7 @@ func set(value string, argsIndex int, args ...interface{}) error {
switch a := arg.(type) { switch a := arg.(type) {
case sql.Scanner: case sql.Scanner:
if err := a.Scan(value); nil != err { if err := a.Scan(value); nil != err {
return newScanErrorComplainer(err, argsIndex, fmt.Sprintf("%T", arg)) return newScanError(err, argsIndex, fmt.Sprintf("%T", arg))
} }
case *string: case *string:
*a = value *a = value