Skip to content

Commit

Permalink
Move ops.SentinelError to types.SentinelError
Browse files Browse the repository at this point in the history
This feel better than having different packages depend on the ops
package just for the SentinelError definition.
  • Loading branch information
mbland committed May 16, 2023
1 parent 5233d8f commit ce4dc07
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
3 changes: 1 addition & 2 deletions db/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package db
import (
"context"

"github.com/mbland/elistman/ops"
"github.com/mbland/elistman/types"
)

Expand All @@ -20,7 +19,7 @@ type Database interface {
//
// Database.Get returns this error when the underlying database request
// succeeded, but there was no such Subscriber.
const ErrSubscriberNotFound = ops.SentinelError("is not a subscriber")
const ErrSubscriberNotFound = types.SentinelError("is not a subscriber")

// A SubscriberProcessor performs an operation on a Subscriber.
//
Expand Down
3 changes: 2 additions & 1 deletion handler/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/google/uuid"
"github.com/mbland/elistman/ops"
"github.com/mbland/elistman/types"
)

//go:generate go run golang.org/x/tools/cmd/stringer -type=eventOperationType
Expand Down Expand Up @@ -57,7 +58,7 @@ type ParseError struct {

// Inspired by the example from the "Customizing error tests with Is and As
// methods" section of https://go.dev/blog/go1.13-errors.
const ErrUserInput = ops.SentinelError("invalid user input")
const ErrUserInput = types.SentinelError("invalid user input")

func (e *ParseError) Error() string {
return e.Type.String() + ": " + e.Message
Expand Down
12 changes: 2 additions & 10 deletions ops/errors.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
package ops

// SentinelError is type for defining constant error values.
//
// Inspired by: https://dave.cheney.net/2019/06/10/constant-time
type SentinelError string

// Error returns the string value of a SentinelError.
func (e SentinelError) Error() string {
return string(e)
}
import "github.com/mbland/elistman/types"

// ErrExternal indicates that a request to an upstream service failed.
//
// handler.Handler checks for this error in order to return an HTTP 502 when
// applicable.
const ErrExternal = SentinelError("external error")
const ErrExternal = types.SentinelError("external error")
11 changes: 11 additions & 0 deletions types/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package types

// SentinelError is type for defining constant error values.
//
// Inspired by: https://dave.cheney.net/2019/06/10/constant-time
type SentinelError string

// Error returns the string value of a SentinelError.
func (e SentinelError) Error() string {
return string(e)
}

0 comments on commit ce4dc07

Please sign in to comment.