Skip to content
Snippets Groups Projects

Handling ValueError exception when commands executed

1 file
+ 7
7
Compare changes
  • Side-by-side
  • Inline
+ 7
7
@@ -118,7 +118,12 @@ class lazy_credential():
@@ -118,7 +118,12 @@ class lazy_credential():
def value(self):
def value(self):
if self._cached_value:
if self._cached_value:
return self._cached_value
return self._cached_value
v = keyring.get_password(*self.args)
try:
 
v = keyring.get_password(*self.args)
 
except ValueError as e:
 
raise click.ClickException("Error while retrieving password from keyring: {}. Your password may be incorrect.".format(e.args[0]))
 
except Exception as e:
 
raise click.ClickException("Error while retrieving password from keyring: {}".format(e.args[0]))
self._cached_value = v
self._cached_value = v
return v
return v
@@ -141,12 +146,7 @@ def set_server(ctx, url, token, use_auth=True):
@@ -141,12 +146,7 @@ def set_server(ctx, url, token, use_auth=True):
parsed = urllib.parse.urlparse(url)
parsed = urllib.parse.urlparse(url)
ctx.obj["SERVER_NETLOC"] = parsed.netloc
ctx.obj["SERVER_NETLOC"] = parsed.netloc
ctx.obj["SERVER_PROTOCOL"] = parsed.scheme
ctx.obj["SERVER_PROTOCOL"] = parsed.scheme
try:
token = (token or lazy_credential(url, "_")) if use_auth else None
token = (token or lazy_credential(url, "_")) if use_auth else None
except ValueError as e:
raise click.ClickException("Error while retrieving password from keyring: {}. Your password may be incorrect.".format(e.args[0]))
except Exception as e:
raise click.ClickException("Error while retrieving password from keyring: {}".format(e.args[0]))
ctx.obj["remote"] = api.get_api(
ctx.obj["remote"] = api.get_api(
domain=ctx.obj["SERVER_NETLOC"],
domain=ctx.obj["SERVER_NETLOC"],
protocol=ctx.obj["SERVER_PROTOCOL"],
protocol=ctx.obj["SERVER_PROTOCOL"],
Loading