[go: up one dir, main page]

ISBN Parser does not handle empty data gracefully

When adding an entry via ISBN which is unknown to the openlibrary API, it returns an empty dictionary (e.g. https://openlibrary.org/api/books?bibkeys=ISBN:3860704443&jscmd=data&format=json). This breaks CoBib as it runs into an IndexError:

% cobib -vv -c cobib/docs/debug.ini add -i 3860704443
2020-11-01 13:16:36,446 [INFO] __main__ main:60 Logging level set to DEBUG.
2020-11-01 13:16:36,447 [INFO] cobib.config set_config:94 Loading configuration from cobib/docs/debug.ini
2020-11-01 13:16:36,451 [INFO] cobib.config validate:107 Validating the runtime configuration.
2020-11-01 13:16:36,451 [DEBUG] cobib.config validate:110 Validing the DATABASE configuration section.
2020-11-01 13:16:36,451 [DEBUG] cobib.config validate:124 Validing the FORMAT configuration section.
2020-11-01 13:16:36,451 [DEBUG] cobib.config validate:136 Validing the TUI configuration section.
2020-11-01 13:16:36,451 [DEBUG] cobib.config validate:152 Validing the KEY_BINDINGS configuration section.
2020-11-01 13:16:36,451 [DEBUG] cobib.config validate:158 Validing the COLORS configuration section.
2020-11-01 13:16:36,452 [INFO] cobib.database read_database:31 Loading database file: ./test/example_literature.yaml
2020-11-01 13:16:36,452 [DEBUG] cobib.parser from_yaml:303 Loading YAML data from file: test/example_literature.yaml.
2020-11-01 13:16:36,461 [DEBUG] cobib.parser __init__:73 Initializing entry: einstein
2020-11-01 13:16:36,472 [DEBUG] cobib.parser __init__:73 Initializing entry: latexcompanion
2020-11-01 13:16:36,481 [DEBUG] cobib.parser __init__:73 Initializing entry: knuthwebsite
2020-11-01 13:16:36,482 [DEBUG] cobib.commands.add execute:30 Starting Add command.
2020-11-01 13:16:36,484 [DEBUG] cobib.commands.add execute:71 Adding entries from ISBN '3860704443'.
2020-11-01 13:16:36,484 [INFO] cobib.parser from_isbn:392 Gathering BibTex data for ISBN: 3860704443.
2020-11-01 13:16:36,488 [DEBUG] urllib3.connectionpool _new_conn:939 Starting new HTTPS connection (1): openlibrary.org:443
2020-11-01 13:16:37,423 [DEBUG] urllib3.connectionpool _make_request:433 https://openlibrary.org:443 "GET /api/books?bibkeys=ISBN:3860704443&jscmd=data&format=json HTTP/1.1" 200 None
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/max/Git/cobib/cobib/__main__.py", line 108, in <module>
    main()
  File "/home/max/Git/cobib/cobib/__main__.py", line 86, in main
    subcmd.execute(args.args)
  File "/home/max/Git/cobib/cobib/commands/add.py", line 72, in execute
    new_entries = Entry.from_isbn(largs.isbn)
  File "/home/max/Git/cobib/cobib/parser.py", line 397, in from_isbn
    for key, value in contents[list(contents.keys())[0]].items():
IndexError: list index out of range