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
import (
"fmt"
)
type ScanErrorComplainer interface {
type ScanError interface {
InternalErrorComplainer
ScanErrorComplainer()
ScanError()
WrappedError() error
}
// internalScanErrorComplainer is the only underlying implementation that fits the
// ScanErrorComplainer interface, in this library.
type internalScanErrorComplainer struct {
// internalScanError is the only underlying implementation that fits the
// ScanError interface, in this library.
type internalScanError struct {
wrappedError error
argumentIndex int
argumentType string
}
// newScanErrorComplainer creates a new internalScanErrorComplainer (struct) and
// returns it as a ScanErrorComplainer (interface).
func newScanErrorComplainer(wrappedError error, argumentIndex int, argumentType string) ScanErrorComplainer {
err := internalScanErrorComplainer{
// newScanError creates a new internalScanError (struct) and
// returns it as a ScanError (interface).
func newScanError(wrappedError error, argumentIndex int, argumentType string) ScanError {
err := internalScanError{
wrappedError:wrappedError,
argumentIndex:argumentIndex,
argumentType:argumentType,
@ -34,28 +30,25 @@ func newScanErrorComplainer(wrappedError error, argumentIndex int, argumentType
return &err
}
// Error method is necessary to satisfy the 'error' interface (and the
// ScanErrorComplainer interface).
func (err *internalScanErrorComplainer) Error() string {
// ScanError interface).
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())
return s
}
// InternalErrorComplainer method is necessary to satisfy the 'InternalErrorComplainer' interface.
// It exists to make this error type detectable in a Go type-switch.
func (err *internalScanErrorComplainer) InternalErrorComplainer() {
func (err *internalScanError) InternalErrorComplainer() {
// Nothing here.
}
// ScanErrorComplainer method is necessary to satisfy the 'ScanErrorComplainer' interface.
// ScanError method is necessary to satisfy the 'ScanError' interface.
// It exists to make this error type detectable in a Go type-switch.
func (err *internalScanErrorComplainer) ScanErrorComplainer() {
func (err *internalScanError) ScanError() {
// Nothing here.
}
func (err *internalScanErrorComplainer) WrappedError() error {
func (err *internalScanError) WrappedError() error {
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) {
case sql.Scanner:
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:
*a = value