fractal-analytics-platform / fractal-client

Command-line client for Fractal
https://fractal-analytics-platform.github.io/fractal-client
BSD 3-Clause "New" or "Revised" License
45 stars 1 forks source link

Command `version` should not fail if fractal server is not alive #723

Closed ychiucco closed 4 days ago

ychiucco commented 4 days ago

Right now we have this

poetry run fractal version
ConnectError at http://localhost:8000/api/alive/
Original error: '[Errno 61] Connection refused'
Hint: is http://localhost:8000 alive?

We something like

def version(client: Client, **kwargs) -> Interface:
    try:
        res = client.get(f"{settings.FRACTAL_SERVER}/api/alive/")
        data = res.json()
        server_str = (
            f"\turl: {settings.FRACTAL_SERVER}"
            f"\tversion: {data['version']}"
        )
    except ConnectError:
        server_str = f"\tConnection to '{settings.FRACTAL_SERVER}' refused"

    return Interface(
        retcode=0,
        data=(
            f"Fractal client\n\tversion: {__VERSION__}\n"
            f"Fractal server:\n{server_str}"

        ),
    )

we get

poetry run fractal version
Fractal client
    version: 2.3.0a1
Fractal server:
    Connection to 'http://localhost:8000' refused