mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
fix CLI exception handling
This commit is contained in:
parent
35b0b3a43c
commit
5e92f637a6
2 changed files with 12 additions and 11 deletions
|
@ -107,18 +107,14 @@ def command(s):
|
||||||
wallet_path = kwargs.pop('wallet_path')
|
wallet_path = kwargs.pop('wallet_path')
|
||||||
wallet = daemon.wallets.get(wallet_path)
|
wallet = daemon.wallets.get(wallet_path)
|
||||||
if wallet is None:
|
if wallet is None:
|
||||||
return {'error': "Wallet not loaded. try 'electrum load_wallet'" }
|
raise Exception('wallet not loaded')
|
||||||
kwargs['wallet'] = wallet
|
kwargs['wallet'] = wallet
|
||||||
else:
|
else:
|
||||||
# we are offline. the wallet must have been passed
|
# we are offline. the wallet must have been passed if required
|
||||||
pass
|
wallet = kwargs.get('wallet')
|
||||||
if cmd.requires_password and password is None and wallet.has_password():
|
if cmd.requires_password and password is None and wallet.has_password():
|
||||||
return {'error': 'Password required' }
|
raise Exception('Password required')
|
||||||
try:
|
|
||||||
return await func(*args, **kwargs)
|
return await func(*args, **kwargs)
|
||||||
except Exception as e:
|
|
||||||
#traceback.print_exc(sys.stderr)
|
|
||||||
return {'error':str(e)}
|
|
||||||
return func_wrapper
|
return func_wrapper
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
|
@ -326,10 +326,11 @@ class Daemon(Logger):
|
||||||
except AuthenticationError:
|
except AuthenticationError:
|
||||||
return web.Response(text='Forbidden', status=403)
|
return web.Response(text='Forbidden', status=403)
|
||||||
request = await request.text()
|
request = await request.text()
|
||||||
#self.logger.info(f'handling request: {request}')
|
|
||||||
response = await jsonrpcserver.async_dispatch(request, methods=self.methods)
|
response = await jsonrpcserver.async_dispatch(request, methods=self.methods)
|
||||||
if isinstance(response, jsonrpcserver.response.ExceptionResponse):
|
if isinstance(response, jsonrpcserver.response.ExceptionResponse):
|
||||||
self.logger.error(f"error handling request: {request}", exc_info=response.exc)
|
self.logger.error(f"error handling request: {request}", exc_info=response.exc)
|
||||||
|
# this exposes the error message to the client
|
||||||
|
response.message = str(response.exc)
|
||||||
if response.wanted:
|
if response.wanted:
|
||||||
return web.json_response(response.deserialized(), status=response.http_status)
|
return web.json_response(response.deserialized(), status=response.http_status)
|
||||||
else:
|
else:
|
||||||
|
@ -441,7 +442,11 @@ class Daemon(Logger):
|
||||||
for x in cmd.options:
|
for x in cmd.options:
|
||||||
kwargs[x] = (config_options.get(x) if x in ['password', 'new_password'] else config.get(x))
|
kwargs[x] = (config_options.get(x) if x in ['password', 'new_password'] else config.get(x))
|
||||||
func = getattr(self.cmd_runner, cmd.name)
|
func = getattr(self.cmd_runner, cmd.name)
|
||||||
|
# fixme: not sure how to retrieve message in jsonrpcclient
|
||||||
|
try:
|
||||||
result = await func(*args, **kwargs)
|
result = await func(*args, **kwargs)
|
||||||
|
except Exception as e:
|
||||||
|
result = {'error':str(e)}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def run_daemon(self):
|
def run_daemon(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue