texworld / betterbib

:green_book: Command-line tools for bibliographies.
816 stars 42 forks source link

Running into `KeyError`s #274

Closed kjappelbaum closed 6 months ago

kjappelbaum commented 6 months ago

Again, sorry for opening the issues. But without source code it is impossible for me to debug myself.

I'm trying to format and sync the attached bib file, which is admittedly quite messy, but I keep running into issues.

referencesbib.txt

such as

betterbib format references.bib --sort-fields --align-values --journal-names short --abbrev-first-names
Warning: Don't know how to interpret month = Dec
Warning: Don't know how to interpret month = 12
Traceback (most recent call last):
  File "/Users/kevinmaikjablonka/miniconda3/envs/gemini/bin/betterbib", line 8, in <module>
    sys.exit(main())
  File "<string>", line 3, in wrapper
  File "<string>", line 1493, in _4vLE8
  File "<string>", line 3, in wrapper
  File "<string>", line 1391, in _NGogp
  File "<string>", line 3, in wrapper
  File "<string>", line 1402, in _zhrqm
KeyError: 'first'

or

betterbib sync references.bib --in-place
Warning: Don't know how to interpret month = Dec
Warning: Don't know how to interpret month = 12
Warning: Don't know how to interpret month = 10
Warning: Don't know how to parse name `Shoemaker, Benjamin A and Thiessen, Paul A and Yu, Bo
Syncing... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╺━━━━━━━━━  75% 0:00:01
Traceback (most recent call last):
  File "/Users/kevinmaikjablonka/miniconda3/envs/gemini/bin/betterbib", line 8, in <module>
    sys.exit(main())
  File "<string>", line 3, in wrapper
  File "<string>", line 1493, in _4vLE8
  File "<string>", line 3, in wrapper
  File "<string>", line 1447, in _Y5gJR
  File "<string>", line 3, in wrapper
  File "<string>", line 1329, in _bjGcJ
  File "/Users/kevinmaikjablonka/miniconda3/envs/gemini/lib/python3.10/concurrent/futures/_base.py", line 451, in result
    return self.__get_result()
  File "/Users/kevinmaikjablonka/miniconda3/envs/gemini/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/Users/kevinmaikjablonka/miniconda3/envs/gemini/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "<string>", line 3, in wrapper
  File "<string>", line 1307, in _vPDVp
  File "<string>", line 3, in wrapper
  File "<string>", line 1057, in _7tyXQ
KeyError: 'type'

using the latest version (7.1.1)

nschloe commented 6 months ago

Fixed now, v7.1.2.

Again, sorry for opening the issues.

Absolutely keep 'em coming!

kjappelbaum commented 6 months ago

Thanks for the fast turnaround!

kjappelbaum commented 6 months ago

Hmm... I somehow still run into it with the file attached above

betterbib sync references.bib --in-place
Warning: Don't know how to parse name `Shoemaker, Benjamin A and Thiessen, Paul A and Yu, Bo
Syncing... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╺━━━━━━━━━━  73% 0:00:01
Traceback (most recent call last):
  File "/Users/kevinmaikjablonka/miniconda3/envs/gemini/bin/betterbib", line 8, in <module>
    sys.exit(main())
  File "<string>", line 3, in wrapper
  File "<string>", line 1505, in _s2WOn
  File "<string>", line 3, in wrapper
  File "<string>", line 1459, in _6g5Hw
  File "<string>", line 3, in wrapper
  File "<string>", line 1438, in _qZvCE
  File "/Users/kevinmaikjablonka/miniconda3/envs/gemini/lib/python3.10/concurrent/futures/_base.py", line 451, in result
    return self.__get_result()
  File "/Users/kevinmaikjablonka/miniconda3/envs/gemini/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/Users/kevinmaikjablonka/miniconda3/envs/gemini/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "<string>", line 3, in wrapper
  File "<string>", line 1416, in _yVpVY
  File "<string>", line 3, in wrapper
  File "<string>", line 1280, in _5lRxn
KeyError: 'type'

with

pip show betterbib
Name: betterbib
Version: 7.1.2
kjappelbaum commented 6 months ago

Ok, first formatting and then syncing works better. But I am not sure if this is what one should a user expect to do.

kjappelbaum commented 6 months ago

and also one more KeyError with (I guess)

@article{bloomberg,
  author       = {Catsaros, Oktavia},
  journal      = {Bloomberg},
  title        = {{Generative AI to Become a $1.3 Trillion Market by 2032, Research Finds}},
  year         = {June 01, 2023},
  howpublished = {www.bloomberg.com/company/press/generative-ai-to-become-a-1-3-trillion-market-by-2032-research-finds}
}

The bibtex file is indeed wrong/strange. But perhaps a useful enhancement would be to more clearly say at which entry it got stuck to help users.

betterbib sync references.bib --in-place -c 2
Warning: Don't know how to parse name `Shoemaker, Benjamin A and Thiessen, Paul A and Yu, Bo
Syncing... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━   0% -:--:--
Warning: Not Found! (404)
Try again later.
Traceback (most recent call last):
  File "/Users/kevinmaikjablonka/miniconda3/envs/gemini/bin/betterbib", line 8, in <module>
    sys.exit(main())
  File "<string>", line 3, in wrapper
  File "<string>", line 1505, in _s2WOn
  File "<string>", line 3, in wrapper
  File "<string>", line 1462, in _6g5Hw
  File "<string>", line 3, in wrapper
  File "<string>", line 650, in _s23jv
  File "<string>", line 3, in wrapper
  File "<string>", line 566, in _q5IG1
  File "<string>", line 3, in wrapper
  File "<string>", line 631, in _2fLjZ
RuntimeError: Unexpected value `June 01, 2023` in field `date-published`
nschloe commented 6 months ago

The date parser will be more robust in the next release.