renamed "InternalErrorComplainer" to "InternalError"

master
Charles Iliya Krempeaux 2019-06-20 21:35:33 -07:00
parent aefae25a79
commit 9a8163782c
7 changed files with 26 additions and 33 deletions

View File

@ -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())
// 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())
// 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())
// 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())
// 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())
// 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())
// 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())
// 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())
// return

View File

@ -1,46 +1,40 @@
package pathmatch
import (
"bytes"
"fmt"
)
const (
internalErrorMessagePrefix = "Internal Error: "
)
type InternalErrorComplainer interface {
type InternalError interface {
error
InternalErrorComplainer()
InternalError()
}
// internalInternalErrorComplainer is the only underlying implementation that fits the
// InternalErrorComplainer interface, in this library.
type internalInternalErrorComplainer struct {
// internalInternalError is the only underlying implementation that fits the
// InternalError interface, in this library.
type internalInternalError struct {
msg string
}
// newInternalErrorComplainer creates a new internalInternalErrorComplainer (struct) and
// returns it as a InternalErrorComplainer (interface).
func newInternalErrorComplainer(format string, a ...interface{}) InternalErrorComplainer {
// newInternalError creates a new internalInternalError (struct) and
// returns it as a InternalError (interface).
func newInternalError(format string, a ...interface{}) InternalError {
msg := fmt.Sprintf(format, a...)
err := internalInternalErrorComplainer{
err := internalInternalError{
msg:msg,
}
return &err
}
// Error method is necessary to satisfy the 'error' interface (and the InternalErrorComplainer
// Error method is necessary to satisfy the 'error' interface (and the InternalError
// interface).
func (err *internalInternalErrorComplainer) Error() string {
func (err *internalInternalError) Error() string {
var buffer bytes.Buffer
buffer.WriteString(internalErrorMessagePrefix)
@ -49,9 +43,8 @@ func (err *internalInternalErrorComplainer) Error() string {
return buffer.String()
}
// 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.
func (err *internalInternalErrorComplainer) InternalErrorComplainer() {
func (err *internalInternalError) InternalError() {
// Nothing here.
}

View File

@ -12,7 +12,7 @@ const (
var (
errThisShouldNeverHappen = newInternalErrorComplainer("This should never happen.")
errThisShouldNeverHappen = newInternalError("This should never happen.")
)

View File

@ -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())
// 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())
// 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.
func (err *internalPatternSyntaxErrorComplainer) BadRequest() {
// Nothing here.

View File

@ -5,7 +5,7 @@ import (
)
type ScanError interface {
InternalErrorComplainer
InternalError
ScanError()
WrappedError() error
}
@ -37,9 +37,9 @@ func (err *internalScanError) Error() string {
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.
func (err *internalScanError) InternalErrorComplainer() {
func (err *internalScanError) InternalError() {
// Nothing here.
}

2
set.go
View File

@ -10,7 +10,7 @@ import (
func set(value string, argsIndex int, args ...interface{}) error {
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 {

View File

@ -346,9 +346,9 @@ func TestSetFail(t *testing.T) {
continue
} else {
switch err.(type) {
case InternalErrorComplainer:
case InternalError:
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
}
case NotEnoughArgumentsComplainer: