gomods / athens

A Go module datastore and proxy
https://docs.gomods.io
MIT License
4.43k stars 499 forks source link

Return 4xx when user has incompatible import path #916

Open leitzler opened 5 years ago

leitzler commented 5 years ago

I have a sample repo that outputs the following error when i run go run main.go:

go: github.com/gofrs/uuid@v0.0.0-20180930033549-48eeef780dd5: go.mod has post-v0 module path "github.com/gofrs/uuid/v3" at revision 48eeef780dd5

The error is due to incorrect import paths in my project, and can be fixed by updating them.

However when I do use athens as proxy, it returns 500 Internal server error:

go: github.com/gofrs/uuid@v0.0.0-20180930033549-48eeef780dd5: unexpected status (http://athens.azurefd.net/github.com/gofrs/uuid/@v/v0.0.0-20180930033549-48eeef780dd5.info): 500 Internal Server Error

As a user I might not have access to the athens logs where the details can be found. Since it is a error introduced by the user, that can be fixed by the user, I suggest that athens returns 4xx instead, like 422 Unprocessable entity.

arschles commented 5 years ago

We return 500 here because we can't get error codes from the go CLI that we use behind the scenes. I think we have two options to fix this:

  1. Apply regular expressions to the CLI output to find out what kind of error the CLI output
  2. Create a bug upstream for the CLI to output structured (i.e. JSON) information that we can read, and return an appropriate error code
arschles commented 5 years ago

@marwan-at-work did you already create the bug I referenced in (2) above? For some reason I remember that you did. If not, I'll create one, just let me know

leitzler commented 5 years ago

I'd vote for (2)

ghost commented 5 years ago

I like 2 as well, if accepted it could be behind a flag so only special use cases such as ours.

In the meantime a few regex for error types might not be a bad idea.