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

Can "connect error" and "ssl error" be part of the public API? #118

Open
rafiss opened this issue May 28, 2022 · 1 comment
Open

Can "connect error" and "ssl error" be part of the public API? #118

rafiss opened this issue May 28, 2022 · 1 comment

Comments

@rafiss
Copy link
Contributor

rafiss commented May 28, 2022

I am working on a CLI tool that uses this library.

Currently, pgconn returns an untyped error for "server refused TLS." See

return nil, errors.New("server refused TLS connection")

This causes some friction, as I need conditional logic based on this error. The only way now is with string matching, which is not guaranteed to be stable across releases.

Can this instead be a public error const, like ErrTLSNotSupported?

Similarly, I need conditional logic for connection errors, but that error is private now. See

type connectError struct {

Can that struct be made publicly visible, similar to PgError?


If you agree, I don't mind working on the PR.

@jackc
Copy link
Owner

jackc commented Jun 3, 2022

I think it is reasonable to make it easier to programmatically handle specific errors.

But error constants and error types become part of the public interface and a tricky part at that. It's much less obvious that there has been a breaking change when a function signature changes than when a returned error changes. This is why I default to untyped / unexported errors.

That said, I think the two changes you suggest are reasonable and may even be optimal, but I'd like you to also consider whether an error interface (like net.Error) or type testing functions (like pgconn.SafeToRetry) would be a better interface. Your original suggestion is probably best but please consider alternatives as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants