tursodatabase / libsql-client-py

Python SDK for libSQL
https://libsql.org/libsql-client-py/
MIT License
44 stars 10 forks source link

Bad error message if URL or token is missing #19

Open penberg opened 10 months ago

penberg commented 10 months ago

An user reports the following error when accidentally removing load_dotenv() call causing to miss URL and access token:

LibsqlError(f”Unsupported URL scheme {config.scheme!r}”, “URL_SCHEME_NOT_SUPPORTED”).
bbennett80 commented 10 months ago

Hello @penberg. First, thank you for your help on Discord, very much appreciated. Second, here is the message error message: LibsqlError: URL_SCHEME_NOT_SUPPORTED: Unsupported URL scheme b''.

I'll look into client.py.

bbennett80 commented 10 months ago

How do you feel about adding another conditional (elif not url) to libsql_client/create_client.py?

def create_client(url: str, *, auth_token: Optional[str] = None) -> Client:
    config = _expand_config(url, auth_token=auth_token)                         
    if config.scheme == "libsql":                                                                              
        config = config._replace(scheme="wss")                                                                 

    if config.scheme == "file":                                                                                
        return _create_sqlite3_client(config)                                                                  
    elif config.scheme in ("ws", "wss"):                                                                       
        return _create_hrana_client(config)                                                                    
    elif config.scheme in ("http", "https"):                                                                   
        return _create_http_client(config)                                                                     
    elif not url:                                                                                              
        raise LibsqlError(f"Database URL is {url}.", "URL_UNDEFINED")           
    else:
        raise LibsqlError(
            f"Unsupported URL scheme {config.scheme!r}", "URL_SCHEME_NOT_SUPPORTED"
        )

It appears that an error for no JWT is handled well from libsql_client/hrana/conn.py inside def _receive.