pkg / errors

Simple error handling primitives
https://godoc.org/github.com/pkg/errors
BSD 2-Clause "Simplified" License
8.18k stars 691 forks source link

fix `func Cause(error) error` returning nil on the root cause error #221

Closed win-t closed 2 years ago

win-t commented 4 years ago

Some error struct have Cause() error method indicating the cause of the error, but that method could return nil indicating that that itself is the root cause in the error chain

look at this struct

type myError struct {
  message string
  cause   error
}

func (m *myError) Error() string { ... }

func (m *myError) Cause() error {
  return m.cause
}

func New(message string) error {
  return &myError{message: message}
}
davecheney commented 4 years ago

Can you please add a test so this change is not accidentally reverted in the future. Thank you.

On 15 Jan 2020, at 19:16, Kurnia D Win notifications@github.com wrote:

 Some error struct have Cause() error method indicating the cause of the error, but that method could return nil indicating that that itself is the root cause in the error chain

look at this struct

type myError struct { message string cause error }

func (m *myError) Error() string { ... }

func (m *myError) Cause() error { return m.cause }

func New(message string) error { return &myError{message: message} } You can view, comment on, or merge this pull request online at:

https://github.com/pkg/errors/pull/221

Commit Summary

fix Cause File Changes

M errors.go (6) Patch Links:

https://github.com/pkg/errors/pull/221.patch https://github.com/pkg/errors/pull/221.diff — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

puellanivis commented 4 years ago

Also, this is a duplicate of https://github.com/pkg/errors/pull/143