Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to indicate bad args #302

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ import (
"github.com/pkg/errors"
)

// ErrBadArgs allows connectors to indicate to their upstreams
// that something about the args they recieved for a particular operation
// are not valid.
type ErrBadArgs struct {
msg string
}

func NewErrBadArgs(msg string) error {
return &ErrBadArgs{
msg: msg,
}
}

// Error returns the error message for an ErrBadArgs error.
func (e *ErrBadArgs) Error() string {
return e.msg
}

// ErrorIsBadArgs checks if the error is an "ErrBadArgs".
func ErrorIsBadArgs(err error) bool {
_, ok := errors.Cause(err).(*ErrBadArgs)
return ok
}

//go:generate stringer -type=Operator

// Operator defines an operator against some data for range scans
Expand Down
16 changes: 16 additions & 0 deletions connector_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dosa

import (
"testing"

"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)

func TestErrorIsBadArgs(t *testing.T) {
badArgsErr := NewErrBadArgs("you can't use that!")
assert.True(t, ErrorIsBadArgs(badArgsErr))

regErr := errors.New("hello")
assert.False(t, ErrorIsBadArgs(regErr))
}