Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pointer receiver on pq.Error.Error() #1083

Merged
merged 1 commit into from Sep 6, 2022

Commits on May 25, 2022

  1. Use pointer receiver on pq.Error.Error()

    The library returns *pq.Error and not pq.Error.
    
    By using a value receiver, the library was documenting that consumers
    should expect returned error values to contain pq.Error.
    
    While *pq.Error implements all methods on pq.Error, *pq.Error is not
    assignable to pq.Error and so you can't type assert an error value into
    pq.Error if it actually contains *pq.Error.
    
    In particular, this is a problem with errors.As. The following if
    condition will always return false.
    
        var pqe pq.Error
        if errors.As(err, &pqe) {
          // Never reached as *pq.Error is not assignable to pqe.
          ...
        }
    nhooyr committed May 25, 2022
    Copy the full SHA
    89fee89 View commit details
    Browse the repository at this point in the history