Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Credentials: handling password credentials error #2354

Merged
merged 1 commit into from
Jun 2, 2017
Merged

[FIX] Credentials: handling password credentials error #2354

merged 1 commit into from
Jun 2, 2017

Conversation

jerneju
Copy link
Contributor

@jerneju jerneju commented May 30, 2017

Issue

biolab/orange3-text#253

Description of changes

try except block

Includes
  • Code changes
  • Tests
  • Documentation

try:
return keyring.get_password(self.service_name, item)
except Exception:
return ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we default to None as is returned when the key is not yet set?

>>> import keyring
>>> print(keyring.get_password('Orange3 - random test', 'nonexistent key')
None

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

@@ -32,7 +32,10 @@ def __setattr__(self, key, value):
keyring.set_password(self.service_name, key, value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the setter also raise e.g. if the keyring isn't unlocked?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does.

@codecov-io
Copy link

codecov-io commented May 30, 2017

Codecov Report

Merging #2354 into master will decrease coverage by 0.02%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #2354      +/-   ##
==========================================
- Coverage   73.37%   73.35%   -0.03%     
==========================================
  Files         317      317              
  Lines       55570    55615      +45     
==========================================
+ Hits        40777    40797      +20     
- Misses      14793    14818      +25

except Exception:
log.error("Failed to get password for '{}'.".format(self.service_name),
exc_info=True)
return None

def __delattr__(self, item):
keyring.delete_password(self.service_name, item)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the deleter, then, also raise?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sure it can. For instance:

# keyring.errors.PasswordDeleteError: No such password!
# RuntimeError:

Copy link
Contributor

@nikicc nikicc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you catch more specific exceptions? PasswordSetError and PasswordDeleteError from https://github.com/jaraco/keyring/blob/master/keyring/errors.py#L3 should do the trick.

@jerneju
Copy link
Contributor Author

jerneju commented Jun 1, 2017

@jerneju jerneju changed the title [WIP][FIX] Credentials: handling password credentials error [FIX] Credentials: handling password credentials error Jun 1, 2017
@nikicc nikicc added this to the 3.4.3 milestone Jun 2, 2017
@kernc kernc merged commit 29fd47b into biolab:master Jun 2, 2017
@jerneju jerneju deleted the error-credentials branch June 2, 2017 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants