libsql-client-py icon indicating copy to clipboard operation
libsql-client-py copied to clipboard

Bad error message if URL or token is missing

Open penberg opened this issue 2 years ago • 2 comments

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”).

penberg avatar Nov 08 '23 07:11 penberg

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 avatar Nov 09 '23 01:11 bbennett80

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.

bbennett80 avatar Nov 09 '23 02:11 bbennett80