Skip to content

Commit

Permalink
Panic if Failed or Partial result is created with nil error.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpfourny committed Apr 7, 2024
1 parent 1c3064c commit 7a79ab5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/res/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,20 @@ func OK[T any](val T) Success[T] {
}

// Partial returns a partially-successful result with the provided value and error.
// Panics if the error is nil.
func Partial[T any](val T, err error) PartialSuccess[T] {
if err == nil {
panic("error must be non-nil")
}
return PartialSuccess[T]{Val: val, Err: err}
}

// Fail returns a failed result with the provided error.
// Panics if the error is nil.
func Fail[T any](err error) Failure[T] {
if err == nil {
panic("error must be non-nil")
}
return Failure[T]{Err: err}
}

Expand Down

0 comments on commit 7a79ab5

Please sign in to comment.