Skip to content

Commit

Permalink
ENH: Provide more informative message whenever using older citeproc w…
Browse files Browse the repository at this point in the history
…ithout encoding arg

Elderly me forgot details of the issue since it happened years ago.
So to get better idea when things fail - provide information that it
is due to outdated citeproc
  • Loading branch information
yarikoptic committed Mar 1, 2019
1 parent 97e9762 commit d1d5cf4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions duecredit/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from .config import CACHE_DIR, DUECREDIT_FILE
from .entries import BibTeX, Doi, Text, Url
from .log import lgr
from .versions import external_versions

_PREFERRED_ENCODING = locale.getpreferredencoding()
platform_system = platform.system().lower()
Expand Down Expand Up @@ -310,8 +311,16 @@ def format_bibtex(bibtex_entry, style='harvard1'):
# we should be able to provide encoding argument
bib_source = cpBibTeX(fname, encoding='utf-8')
except Exception as e:
lgr.error("Failed to process BibTeX file %s: %s" % (fname, e))
return "ERRORED: %s" % str(e)
msg = "Failed to process BibTeX file %s: %s." % (fname, e)
citeproc_version = external_versions['citeproc']
if 'unexpected keyword argument' in str(e) and \
citeproc_version and citeproc_version < '0.4':
err = "need a newer citeproc-py >= 0.4.0"
msg += " You might just " + err
else:
err = str(e)
lgr.error(msg)
return "ERRORED: %s" % err
finally:
# return warnings back
warnings.filters = old_filters
Expand Down

0 comments on commit d1d5cf4

Please sign in to comment.