-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: x/tools/go/packages: Improve error handling capabilities #69950
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
Comments
|
While I was writing the example I realized that the returned value is not an Suggested solution: add more detailed values to
|
Doesn't that mean you're just shifting the string matching into x/tools/go/packages ? |
I don't think ErrorKind is the right place for this information; its purpose is to report which layer of the system produced the error: metadata, syntax, or types. (Of course, I'm not sure I understand the distinction between MissingError and NotExistError either. Isn't it the case that if a "package...does not exist" then the "package is missing from the project"? There is a related proposal to provide a public API to discriminate all the errors produced by the type checker. If that proposal advances, then it would make sense for the packages.Error struct to have another field (e.g. See: |
Yes, but it is easier to track in the x package than for all users of x/tools/go/packages. Also, when this package is merged into the main branch, it will be possible to use common constants. An alternative option is more complex, but in my opinion more correct - it is to generate the ErrorKind value (or something from which it can be unambiguously obtained) on the go toolchain side and add it to the output of commands that use loaders |
MissingError for cases when the package exists at all, but is not in the project. In this case, when importing, compilation fails with this error NotExistError is about the fact that the package does not exist at all. For example, go get makes an HTTP request to $GOPROXY and receives the status code 404. In the case of "direct", this can also be implemented at the level of requests to the VCS |
"Not found" in the proxy (or a proxy) doesn't mean it doesn't exist at all. Perhaps the proxy is incomplete, or requires authentication before it reveals that a module exists. Trying to account for errors at this level of detail often devolves into a fractal of complexity. What about non- |
I could be wrong, but it looks like proxy.golang.org returns 404 only if the package really doesn't exist. Although, of course, this is not required by the GOPROXY protocol |
Timed out in state WaitingForInfo. Closing. (I am just a bot, though. Please speak up if this is a mistake or you have the requested information.) |
Proposal Details
I want to handle src/cmd/go/internal/modload.ImportMissingError in my application, but it seems that currently it is possible only via
strings.Contains(err.Error(), somePattern)
, which is bad practiceThe text was updated successfully, but these errors were encountered: