https://golang.org/doc/faq#nil_error

Make Validate return error, not MultiError.

-Caleb

On Fri, Jul 1, 2016 at 5:04 PM, Kevin Manley <kevin.man...@gmail.com> wrote:
> I am new to Go so I'm sure this is just me misunderstanding how things work,
> but I was surprised at this result. Please can someone help me understand
> why the return value from Validate() is not seen as nil by the caller,
> despite Validate() returning nil?
> TIA, Kevin
>
> https://play.golang.org/p/UF4EYwOQ-n
>
> package main
>
> import (
> "fmt"
> )
>
> type MultiError map[string]error
>
> func (e MultiError) Error() string {
> return fmt.Sprintf("%d errors", len(e))
> }
>
> func Validate() MultiError {
> return nil
> }
>
> func main() {
> var err error
> err = Validate()
> if err == nil {
> fmt.Println("err is nil, as expected")
> } else {
> fmt.Println("err is not nil!!: ", err)
> }
> }
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to