buffalo

show can set disabled pop error: mysql select one: sql: no rows in result set


err = db.Find(model)
err == "mysql select one: sql: no rows in result set"

I don't think this is a mistake. How do I turn it off in buffalo/pop?

and


errors.Is(err, sql.ErrNoRows)   === false


can't unwrap the error

    fmt.Println(111)
    for {
        fmt.Println("err:", err,err.Error(),reflect.TypeOf(err))
        err = errors.Unwrap(err)
        if err == nil {
            break
        }
    }
    fmt.Println(222)


err: mysql select one: sql: no rows in result set mysql select one: sql: no rows in result set *errors.withStack



Solution

  • buffalo/pop still uses the pkg/errors package (https://godoc.org/github.com/pkg/errors) to wrap its errors. While it's still the case, you can use errors.Cause method from this package, and compare it to the sql.ErrNoRows error.

    if errors.Cause(err) == sql.ErrNoRows {
    // Do what you need here.
    }