renamed "InternalErrorComplainer" to "InternalError"
parent
aefae25a79
commit
9a8163782c
|
@ -19,7 +19,7 @@ package pathmatch
|
||||||
// fmt.Printf("Something you did when you called pathmatch.Compile() caused an error. The error message was....\n%s\n", err.Error())
|
// fmt.Printf("Something you did when you called pathmatch.Compile() caused an error. The error message was....\n%s\n", err.Error())
|
||||||
// return
|
// return
|
||||||
//
|
//
|
||||||
// case pathmatch.InternalErrorComplainer:
|
// case pathmatch.InternalError:
|
||||||
//
|
//
|
||||||
// fmt.Printf("It's not your fault; it's our fault. Something bad happened internally when pathmatch.Compile() was running. The error message was....\n%s\n", err.Error())
|
// fmt.Printf("It's not your fault; it's our fault. Something bad happened internally when pathmatch.Compile() was running. The error message was....\n%s\n", err.Error())
|
||||||
// return
|
// return
|
||||||
|
@ -46,7 +46,7 @@ package pathmatch
|
||||||
// fmt.Printf("Something you did when you called pathmatch.Compile() caused an error. The error message was....\n%s\n", err.Error())
|
// fmt.Printf("Something you did when you called pathmatch.Compile() caused an error. The error message was....\n%s\n", err.Error())
|
||||||
// return
|
// return
|
||||||
//
|
//
|
||||||
// case pathmatch.InternalErrorComplainer:
|
// case pathmatch.InternalError:
|
||||||
//
|
//
|
||||||
// fmt.Printf("It's not your fault; it's our fault. Something bad happened internally when pathmatch.Compile() was running. The error message was....\n%s\n", err.Error())
|
// fmt.Printf("It's not your fault; it's our fault. Something bad happened internally when pathmatch.Compile() was running. The error message was....\n%s\n", err.Error())
|
||||||
// return
|
// return
|
||||||
|
@ -70,7 +70,7 @@ package pathmatch
|
||||||
// fmt.Printf("Something you did when you called pattern.Match() caused an error. The error message was....\n%s\n", err.Error())
|
// fmt.Printf("Something you did when you called pattern.Match() caused an error. The error message was....\n%s\n", err.Error())
|
||||||
// return
|
// return
|
||||||
//
|
//
|
||||||
// case pathmatch.InternalErrorComplainer:
|
// case pathmatch.InternalError:
|
||||||
//
|
//
|
||||||
// fmt.Printf("It's not your fault; it's our fault. Something bad happened internally when pattern.Match() was running. The error message was....\n%s\n", err.Error())
|
// fmt.Printf("It's not your fault; it's our fault. Something bad happened internally when pattern.Match() was running. The error message was....\n%s\n", err.Error())
|
||||||
// return
|
// return
|
||||||
|
@ -103,7 +103,7 @@ package pathmatch
|
||||||
// fmt.Printf("Something you did when you called pathmatch.Compile() caused an error. The error message was....\n%s\n", err.Error())
|
// fmt.Printf("Something you did when you called pathmatch.Compile() caused an error. The error message was....\n%s\n", err.Error())
|
||||||
// return
|
// return
|
||||||
//
|
//
|
||||||
// case pathmatch.InternalErrorComplainer:
|
// case pathmatch.InternalError:
|
||||||
//
|
//
|
||||||
// fmt.Printf("It's not your fault; it's our fault. Something bad happened internally when pathmatch.Compile() was running. The error message was....\n%s\n", err.Error())
|
// fmt.Printf("It's not your fault; it's our fault. Something bad happened internally when pathmatch.Compile() was running. The error message was....\n%s\n", err.Error())
|
||||||
// return
|
// return
|
||||||
|
|
|
@ -1,46 +1,40 @@
|
||||||
package pathmatch
|
package pathmatch
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
internalErrorMessagePrefix = "Internal Error: "
|
internalErrorMessagePrefix = "Internal Error: "
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type InternalError interface {
|
||||||
type InternalErrorComplainer interface {
|
|
||||||
error
|
error
|
||||||
InternalErrorComplainer()
|
InternalError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// internalInternalError is the only underlying implementation that fits the
|
||||||
// internalInternalErrorComplainer is the only underlying implementation that fits the
|
// InternalError interface, in this library.
|
||||||
// InternalErrorComplainer interface, in this library.
|
type internalInternalError struct {
|
||||||
type internalInternalErrorComplainer struct {
|
|
||||||
msg string
|
msg string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newInternalError creates a new internalInternalError (struct) and
|
||||||
// newInternalErrorComplainer creates a new internalInternalErrorComplainer (struct) and
|
// returns it as a InternalError (interface).
|
||||||
// returns it as a InternalErrorComplainer (interface).
|
func newInternalError(format string, a ...interface{}) InternalError {
|
||||||
func newInternalErrorComplainer(format string, a ...interface{}) InternalErrorComplainer {
|
|
||||||
msg := fmt.Sprintf(format, a...)
|
msg := fmt.Sprintf(format, a...)
|
||||||
|
|
||||||
err := internalInternalErrorComplainer{
|
err := internalInternalError{
|
||||||
msg:msg,
|
msg:msg,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &err
|
return &err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Error method is necessary to satisfy the 'error' interface (and the InternalError
|
||||||
// Error method is necessary to satisfy the 'error' interface (and the InternalErrorComplainer
|
|
||||||
// interface).
|
// interface).
|
||||||
func (err *internalInternalErrorComplainer) Error() string {
|
func (err *internalInternalError) Error() string {
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
|
|
||||||
buffer.WriteString(internalErrorMessagePrefix)
|
buffer.WriteString(internalErrorMessagePrefix)
|
||||||
|
@ -49,9 +43,8 @@ func (err *internalInternalErrorComplainer) Error() string {
|
||||||
return buffer.String()
|
return buffer.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InternalError method is necessary to satisfy the 'InternalError' 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 *internalInternalErrorComplainer) InternalErrorComplainer() {
|
func (err *internalInternalError) InternalError() {
|
||||||
// Nothing here.
|
// Nothing here.
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ const (
|
||||||
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errThisShouldNeverHappen = newInternalErrorComplainer("This should never happen.")
|
errThisShouldNeverHappen = newInternalError("This should never happen.")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ import (
|
||||||
// fmt.Printf("Something you did when you called pathmatch.Compile() caused an error. The error message was....\n%s\n", err.Error())
|
// fmt.Printf("Something you did when you called pathmatch.Compile() caused an error. The error message was....\n%s\n", err.Error())
|
||||||
// return
|
// return
|
||||||
//
|
//
|
||||||
// case pathmatch.InternalErrorComplainer:
|
// case pathmatch.InternalError:
|
||||||
//
|
//
|
||||||
// fmt.Printf("It's not your fault; it's our fault. Something bad happened internally when pathmatch.Compile() was running. The error message was....\n%s\n", err.Error())
|
// fmt.Printf("It's not your fault; it's our fault. Something bad happened internally when pathmatch.Compile() was running. The error message was....\n%s\n", err.Error())
|
||||||
// return
|
// return
|
||||||
|
@ -71,7 +71,7 @@ func (err *internalPatternSyntaxErrorComplainer) Error() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// BadRequest method is necessary to satisfy the 'InternalErrorComplainer' interface.
|
// BadRequest method is necessary to satisfy the 'InternalError' 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 *internalPatternSyntaxErrorComplainer) BadRequest() {
|
func (err *internalPatternSyntaxErrorComplainer) BadRequest() {
|
||||||
// Nothing here.
|
// Nothing here.
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ScanError interface {
|
type ScanError interface {
|
||||||
InternalErrorComplainer
|
InternalError
|
||||||
ScanError()
|
ScanError()
|
||||||
WrappedError() error
|
WrappedError() error
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,9 @@ func (err *internalScanError) Error() string {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// InternalErrorComplainer method is necessary to satisfy the 'InternalErrorComplainer' interface.
|
// InternalError method is necessary to satisfy the 'InternalError' 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 *internalScanError) InternalErrorComplainer() {
|
func (err *internalScanError) InternalError() {
|
||||||
// Nothing here.
|
// Nothing here.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
set.go
2
set.go
|
@ -10,7 +10,7 @@ import (
|
||||||
func set(value string, argsIndex int, args ...interface{}) error {
|
func set(value string, argsIndex int, args ...interface{}) error {
|
||||||
|
|
||||||
if 0 > argsIndex {
|
if 0 > argsIndex {
|
||||||
return newInternalErrorComplainer("Index value %d is less than zero.", argsIndex)
|
return newInternalError("Index value %d is less than zero.", argsIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
if lenArgs := len(args); argsIndex >= lenArgs {
|
if lenArgs := len(args); argsIndex >= lenArgs {
|
||||||
|
|
|
@ -346,9 +346,9 @@ func TestSetFail(t *testing.T) {
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
case InternalErrorComplainer:
|
case InternalError:
|
||||||
if expected, actual := internalError, test.ExpectedFit; expected != actual {
|
if expected, actual := internalError, test.ExpectedFit; expected != actual {
|
||||||
t.Errorf("For test #%d, did indeed expect an error, but did not expect it to fit the \"InternalErrorComplainer\" interface, but actually did: %T.", testNumber, err)
|
t.Errorf("For test #%d, did indeed expect an error, but did not expect it to fit the \"InternalError\" interface, but actually did: %T.", testNumber, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
case NotEnoughArgumentsComplainer:
|
case NotEnoughArgumentsComplainer:
|
||||||
|
|
Loading…
Reference in New Issue