2016-02-25 22:59:38 +00:00
|
|
|
package pathmatch
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2019-06-21 04:28:51 +00:00
|
|
|
type ScanError interface {
|
2016-02-25 22:59:38 +00:00
|
|
|
InternalErrorComplainer
|
2019-06-21 04:28:51 +00:00
|
|
|
ScanError()
|
2016-02-25 22:59:38 +00:00
|
|
|
WrappedError() error
|
|
|
|
}
|
|
|
|
|
2019-06-21 04:28:51 +00:00
|
|
|
// internalScanError is the only underlying implementation that fits the
|
|
|
|
// ScanError interface, in this library.
|
|
|
|
type internalScanError struct {
|
2016-02-25 22:59:38 +00:00
|
|
|
wrappedError error
|
|
|
|
argumentIndex int
|
|
|
|
argumentType string
|
|
|
|
}
|
|
|
|
|
2019-06-21 04:28:51 +00:00
|
|
|
// newScanError creates a new internalScanError (struct) and
|
|
|
|
// returns it as a ScanError (interface).
|
|
|
|
func newScanError(wrappedError error, argumentIndex int, argumentType string) ScanError {
|
|
|
|
err := internalScanError{
|
2016-02-25 22:59:38 +00:00
|
|
|
wrappedError:wrappedError,
|
|
|
|
argumentIndex:argumentIndex,
|
|
|
|
argumentType:argumentType,
|
|
|
|
}
|
|
|
|
|
|
|
|
return &err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Error method is necessary to satisfy the 'error' interface (and the
|
2019-06-21 04:28:51 +00:00
|
|
|
// ScanError interface).
|
|
|
|
func (err *internalScanError) Error() string {
|
2016-02-25 22:59:38 +00:00
|
|
|
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.
|
2019-06-21 04:28:51 +00:00
|
|
|
func (err *internalScanError) InternalErrorComplainer() {
|
2016-02-25 22:59:38 +00:00
|
|
|
// Nothing here.
|
|
|
|
}
|
|
|
|
|
2019-06-21 04:28:51 +00:00
|
|
|
// ScanError method is necessary to satisfy the 'ScanError' interface.
|
2016-02-25 22:59:38 +00:00
|
|
|
// It exists to make this error type detectable in a Go type-switch.
|
2019-06-21 04:28:51 +00:00
|
|
|
func (err *internalScanError) ScanError() {
|
2016-02-25 22:59:38 +00:00
|
|
|
// Nothing here.
|
|
|
|
}
|
|
|
|
|
2019-06-21 04:28:51 +00:00
|
|
|
func (err *internalScanError) WrappedError() error {
|
2016-02-25 22:59:38 +00:00
|
|
|
return err.wrappedError
|
|
|
|
}
|