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

Fixing error return for missing month #5

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

bnlawrence
Copy link

I was getting this

bibble bib/pubs.bib bib/publications.tmpl > _includes/pubs.html
Traceback (most recent call last):
  File "/home/bnl/anaconda2/bin/bibble", line 11, in <module>
    sys.exit(main())
  File "/home/bnl/anaconda2/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/bnl/anaconda2/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/bnl/anaconda2/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/bnl/anaconda2/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/bnl/anaconda2/lib/python2.7/site-packages/bibble/main.py", line 162, in main
    out = tmpl.render(entries=bib_sorted)
  File "/home/bnl/anaconda2/lib/python2.7/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/home/bnl/anaconda2/lib/python2.7/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "<template>", line 12, in top-level template code
  File "/home/bnl/anaconda2/lib/python2.7/site-packages/bibble/main.py", line 119, in _month_name
    return month_name[int(monthnum)]
jinja2.exceptions.UndefinedError: 'pybtex.database.FieldDict object' has no attribute 'month'

This didn't turn out to be an AttributeError, which was my first attempt, so I gave up and just put a tran for any raw Exception in ... but I think that's probably what you want anyway ... unless you want it to log an error ...

@sampsyo
Copy link
Owner

sampsyo commented Feb 3, 2018

Thanks for looking into this!

Handling general Exceptions can make debugging hard—for example, it will even silently suppress stuff like NameError and KeyboardInterrupt.

Do you know which exception was actually being raised from that line? Is there a straightforward way to reproduce the problem so I can look a little more closely?

@bnlawrence
Copy link
Author

Sorry ... gmail gobbled up your comment notification (ok, my incorrectly set filter did the gobbling) ...

I can't repeat it right now since I've gone down a rabbit hole associated with the next error ... when/if I come back up I'll see if I can generate some simple test cases ... (I need to overwrite some of your methods anyway, since I'm using zotero's better_biblatex export, not vanilla bibtex ... and now I have unicode errors as well, so need to make it work with python3 ...)

@bnlawrence
Copy link
Author

bnlawrence commented Feb 12, 2018

Meanwhile, here is a vanilla bibtex file which delivers the error (which is coming from pybtex, which is why it's hard to trap sensibly):

@article{lawrence_crossing_2018,
	title = {Crossing the {Chasm}: {How} to develop weather and climate models for next generation computers.},
	doi = {10.5194/gmd-2017-186},
	journal = {Geoscientific Model Development Discussions},
	author = {Lawrence, Bryan N. and {Mike Rezny} and {Reinhard Budich} and {Peter Bauer} and {Jörg Behrens} and {Mick Carter} and {Willem Deconinck} and {Rupert Ford} and {Christopher Maynard} and {Steve Mullerworth} and {Carlos Osuna} and {Andy Porter} and {Kim Serradell} and {Sophie Valcke} and {Nils Wedi} and {Simon Wilson}},
	year = {2018},
	note = {bibtex:LawChasm17},
	keywords = {bnl, prp17, onblog, aces}
}

It's clearly the absence of a date field which causes the problem ...

@sampsyo
Copy link
Owner

sampsyo commented Feb 12, 2018

That's odd—I just ran this entry through bibble using the included template (simple.html):

$ bibble foo.bib simple.html

and it worked fine! I used Python 3.6.4 and Pybtex 0.21. Not sure what's going wrong.

@bnlawrence
Copy link
Author

Ah. I'm using someone else's template ... let me investigate!

@bnlawrence
Copy link
Author

Ok, it arises from the use of {{ entry.fields['month'] | monthname }} in the template ... without the custom filter it's fine.

@ransford
Copy link
Collaborator

Side note, probably unrelated: I just noticed that the master branch of this repo (sampsyo/bibble) was ahead of the develop branch, which meant develop lacked the Python 3 fixes that were already in master. (It looks like I failed to push master when making the v0.0.1 release tag.) Just rectified that by merging master into develop.

@sampsyo
Copy link
Owner

sampsyo commented Feb 12, 2018

Aha! Then maybe the right solution is to use {% if entry.fields['month'] %} in the template?

@bnlawrence
Copy link
Author

bnlawrence commented Feb 12, 2018

(Yes, the Python3 fixes were unrelated, I added those back in first.)

You did make the right decision for the template, but given the filters exist, they probably ought not to fail :-). I don't (at the moment) know how to trap the error in a more sophisticated manner than I suggested.

@bnlawrence
Copy link
Author

Well anyway, this is the work around:

 {% set mon = entry.fields['month'] %}
 {% if mon %}
   {{ entry.fields['month'] |monthname }}
 {% endif %}

@bnlawrence
Copy link
Author

(This second commit has the error return fix removed, but I still think it needs some sort of fix :-) )

zacmanchester and others added 11 commits August 3, 2018 17:13
@ransford
Copy link
Collaborator

Should we still think about merging this? @bnlawrence it looks like there may still be a little bit of work left to do?

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