-
Notifications
You must be signed in to change notification settings - Fork 101
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 go error wrapping instead of go-errors in apps #383
Comments
My understanding is - because we want to be backward compatible with the latest two versions of go, we have to wait till 1.14 |
...but to prepare for that I would archive |
I edited the issue desc to clarify that it's about our applications, which must support only last stable 1.13 And I assume that the consensus could (should) be applied to libraries once 1.14 has been released. |
Yes, I heard about that, but frankly still don't get it. What's the difference between library and application. In theory almost every package should behave like library. Application is just a The pilosa would be a good example. We started using it as an external service, but in next iteration we extracted API and got rid of the server part and continue use it as a library. |
@kuba-- I think the main difference is that we don't promise any internal API compatibility for libraries that are part of our app projects. So you could use it as a library, but it may break over time if you don't lock the version. The cause of this difference was mentioned by @creachadair on multiple occasions: SemVer is good, but it's not enough. For example, v1.0 means two different things for application and a library. For the library, v1.0 means that all APIs will work the same way in any future v1.x release (ideally). And for the application, v1.0 means that the application will have the same CLI, on-disk format, external APIs. No promises are given about the structure of internal libraries and APIs. To your point, the solution would be to always write an app as a library in a separate project, have it versioned (thus provide a compatibility promise) and then have a separate project with a server/CLI that calls into the library, and version it separately. But this again forces us to think about libs being different from apps. |
To the topic of the issue, I agree that we should start using the new functionality provided by stdlib Also, before archiving I think adding it to apps first also makes sense because we can try the new API and see if it fully supersedes the |
In my opinion we should paraphrase it - "for For instance if you have a |
@kuba-- I totally agree, it's a good definition and it may solve the concern I raised when mentioning the project split to But there are still problems with this approach, if managed in a single repo. You'll need to version the internal library, but it's nearly impossible to do correctly, because the versions in the repo correspond to app versions, while library users will use them as lib versions. Which is, of course, incorrect since app versions assume a different type of API compatibility in mind. This is why I brought up versioning. |
I think versioning is something orthogonal to this. Here we are talking about the new release (or master development). |
I would wait to take this decision until we are used to the new syntax. I'm not really happy with wrapping an error that you want to catch. Example: if err != nil {
return fmt.Errorf("object not found %w", err)
} If I want to catch "object not found" error this system is not useful. I have to either wrap two errors or create a new struct error with var ErrObjectNotFound = fmt.Errorf("object not found")
if err != nil {
return fmt.Errorf("%w %w", ErrObjectNotFound, err)
} I find the |
@jfontan Can you please give an example where this would be useful? Do you mean that We have a similar case in Babelfish, specifically when processing a source file. We may generate multiple errors for it, but instead of wrapping them that way we have a single I think it may be true for your use case as well: your Note that Also, I find custom types more descriptive: if you try to debug an unknown codebase and print a type of received error, it will always be |
I agree that a custom type for errors is the way to go. What I don't like is that there's not syntactic sugar for something as common as wrapping a normal error whenever is needed and forcing you to create custom types with
I believe that all this boilerplate could be done by a library, be it |
I just want to clarify one thing about the new (If you need compatibility with Go < 1.13, use I don't have a strong position on the API question yet, but I wanted to point that out, since it means you do not (necessarily) need to introduce new custom error types for some of the simple common cases. |
The problem is that |
OK, I think the consensus so far is that we can try using it for projects that support 1.13 exclusively (apps). |
go 1.13
has been released, and our guide says thatgo 1.13
offers error wrapping (errors.Is
,errors.Wrap
...)For error handling, our guide request to use
go-errors
, which also supports error wrapping.Then it was raised the following question on our [private link] Slack
The text was updated successfully, but these errors were encountered: