Skip to content

Commit c9c8b87

Browse files
committed
Wrap creation of zuliprc in try to catch OSError from open.
Previously OSErrors where caught in the outer try in the while loop in parse_zuliprc. This resulted in a misleading error message about invalid credentials. This patch catches OSErrors from open directly at the source, and exits directly since there is no point to keep asking the user for credentials. In particular, when running the default docker configuration, open throws PermissionError since the zulip user in the container does not have permission to create files in the mapped host folder. Fixes #797.
1 parent 5609c78 commit c9c8b87

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

zulipterminal/cli/run.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,17 @@ def fetch_zuliprc(zuliprc_path: str) -> None:
160160
print(in_color('red', "\nIncorrect Email(or Username) or Password!\n"))
161161
res, login_id = get_api_key(realm_url)
162162

163-
with open(zuliprc_path, 'w') as f:
164-
f.write('[api]'
165-
+ '\nemail=' + login_id
166-
+ '\nkey=' + str(res.json()['api_key'])
167-
+ '\nsite=' + realm_url)
168-
print('Generated API key saved at ' + zuliprc_path)
163+
try:
164+
with open(zuliprc_path, 'w') as f:
165+
f.write('[api]'
166+
+ '\nemail=' + login_id
167+
+ '\nkey=' + str(res.json()['api_key'])
168+
+ '\nsite=' + realm_url)
169+
print('Generated API key saved at ' + zuliprc_path)
170+
except OSError as ex:
171+
print(in_color('red', ex.__class__.__name__
172+
+ ": zuliprc could not be created at " + zuliprc_path))
173+
sys.exit(1)
169174

170175

171176
def parse_zuliprc(zuliprc_str: str) -> Dict[str, Any]:

0 commit comments

Comments
 (0)