unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.81k stars 271 forks source link

`lib.install` on invalid project gives a bad error #5334

Open ChrisPenner opened 2 months ago

ChrisPenner commented 2 months ago

If you don't specify a valid project name you get a request dump :'(

focus/main> lib.install potions

  Oops, I received an unexpected status code from the server.

  Here is the request.

    Request
        { requestPath =
            ( BaseUrl
                { baseUrlScheme = Https
                , baseUrlHost = "api.unison-lang.org"
                , baseUrlPort = 443
                , baseUrlPath = ""
                }
            , "/ucm/v1/projects/project"
            )
        , requestQueryString = fromList
            [
                ( "name"
                , Just "potions"
                )
            ]
        , requestBody = Nothing
        , requestAccept = fromList
            [ application/json;charset=utf-8
            , application/json
            ]
        , requestHeaders = fromList []
        , requestHttpVersion = HTTP/1.1
        , requestMethod = "GET"
        }

  Here is the full response.

    Response
        { responseStatusCode = Status
            { statusCode = 400
            , statusMessage = "Invalid Parameter"
            }
        , responseHeaders = fromList
            [
                ( "Server"
                , "nginx/1.24.0"
                )
            ,
                ( "Date"
hojberg commented 2 months ago

this is related to #5205

hojberg commented 2 months ago

Here's a ProjectRef type and parser from the Share UI: https://github.com/unisoncomputing/share-ui/blob/main/src/UnisonShare/Project/ProjectRef.elm

We should check if its valid based in the above before sending the request

hojberg commented 2 months ago

Here's a ticket for generally improving unexpected server response errors: https://github.com/unisonweb/unison/issues/5341

hojberg commented 2 months ago

Suggested error message surrounding project reference parsing:

`potions` looks like an invalid project reference. 
Please try again in the format of: @unison/base.