Skip to content

Commit 7d65093

Browse files
committed
Catch all exceptions from netrc package
1 parent 071b7d4 commit 7d65093

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

alertaclient/auth.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def machine(endpoint):
2020
def get_token(endpoint):
2121
try:
2222
info = netrc(NETRC_FILE)
23-
except OSError:
23+
except Exception:
2424
return
2525
auth = info.authenticators(machine(endpoint))
2626
if auth is not None:
@@ -33,8 +33,8 @@ def save_token(endpoint, username, token):
3333
pass
3434
try:
3535
info = netrc(NETRC_FILE)
36-
except OSError:
37-
raise click.UsageError('Could not write to {}'.format(NETRC_FILE))
36+
except Exception as e:
37+
raise click.UsageError('{}'.format(e))
3838
info.hosts[machine(endpoint)] = (username, None, token)
3939
with open(NETRC_FILE, 'w') as f:
4040
f.write(dump_netrc(info))
@@ -43,14 +43,14 @@ def save_token(endpoint, username, token):
4343
def clear_token(endpoint):
4444
try:
4545
info = netrc(NETRC_FILE)
46-
except OSError:
47-
raise click.UsageError('No {} file.'.format(NETRC_FILE))
46+
except Exception as e:
47+
raise click.UsageError('{}'.format(e))
4848
try:
4949
del info.hosts[machine(endpoint)]
5050
with open(NETRC_FILE, 'w') as f:
5151
f.write(dump_netrc(info))
5252
except KeyError as e:
53-
raise click.UsageError('User not logged in.')
53+
raise click.UsageError('No credentials stored for {}'.format(e))
5454

5555

5656
# See https://bugs.python.org/issue30806

0 commit comments

Comments
 (0)