Skip to content

Commit

Permalink
log 1pass entry name and field on error (#42)
Browse files Browse the repository at this point in the history
* log 1pass entry name and field on error
  • Loading branch information
Brunope authored Jan 31, 2024
1 parent 0c65b5d commit 8594787
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions db_facts/lpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,25 @@ def lpass_field(name: str, field: str) -> str:
# this field.
if field == 'url':
raise NotImplementedError(
'Cannot retrieve notes or URL fields from 1password')
'Cannot retrieve URL field from 1password')

# The field lastpass stored notes in was called "notes", but the field
# 1password stores notes in is called "notesPlain".
if field == 'notes':
field = 'notesPlain'

log = logging.getLogger(__name__)
try:
raw_output = check_output(
['op', 'item', 'get', name, '--field', f'label={field}', '--format=json'])
parsed_output = json.loads(raw_output)
return parsed_output['value']
except (json.JSONDecodeError, TypeError, CalledProcessError) as e:
log = logging.getLogger(__name__)
log.error(f"Error retrieving entry from 1password cli: {e}")
except (CalledProcessError, KeyError):
log.error(
f'Error from 1password CLI retrieving {field} from "{name}".\n' +
'Do you have the 1password CLI installed?\n' +
f'Does the entry {name} exist in your 1password account?\n' +
f'Does this entry have the field: {field}?')
raise


Expand Down
2 changes: 1 addition & 1 deletion db_facts/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '5.1.0'
__version__ = '5.1.1'

0 comments on commit 8594787

Please sign in to comment.