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

Promote more internal errors as part of the public API #50

Open
dominicbarnes opened this issue Oct 9, 2020 · 1 comment
Open

Promote more internal errors as part of the public API #50

dominicbarnes opened this issue Oct 9, 2020 · 1 comment

Comments

@dominicbarnes
Copy link

There are quite a few non-exported error types that are returned by this API, such as parseConfigError and connectError that are not possible to be detected with errors.As or errors.Is. And unfortunately, using Unwrap() on them removes some useful context to determining the failure mode as well.

Would it be possible to include these particular errors (and probably all errors returned by this library) as part of the public API? One possibility is to just export these particular types as-is, with another option being to coalesce them into a single type.

For some context, I work on an application that accepts user input for connection settings in order to interact with their database, so I'm doing my best to handle as many errors as possible to make sure we provide descriptive and actionable error messages. The more structured context we can extract from error values, the better, and unexported types make that tricky if not impossible.

@jackc
Copy link
Owner

jackc commented Oct 12, 2020

I'm conservative about exporting errors because they add to the public interface in a way that can be difficult to guarantee doesn't change. But I'm open to exporting more specific errors if they meet certain criteria.

My primary rule for whether an error should be part of the public interface is if anything can be done with it. i.e. if the error condition is something the calling code cannot do anything different vs. some other unknown error then I don't think it is worth exporting.

In general, I also prefer not to expose the underlying error because that becomes part of the public interface as well (at least in the sense that application code may be relying on it). However, in this case that may be the lesser evil.

Ultimately, what would make it easiest to proceed would be to know the following: when error condition X happens the application should do Y. That would help us decide how best to expose condition X.

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