Skip to content
This repository has been archived by the owner on Dec 27, 2020. It is now read-only.

Change "--verbose" functionality of "test" functionality/Display more useful messages for unparseable files #35

Closed
jrsmith3 opened this issue Feb 26, 2015 · 0 comments

Comments

@jrsmith3
Copy link
Owner

Once issue #34 has been closed, the functionality of the "--verbose" flag should be refactored to output more useful information about the nature of a file's unparseability. Output information should include:

  • The error type.
  • The error message.
  • The literal offending line encountered by the BibTeX parser.
  • The line number of the unparseable line.

This information can be determined by storing and later inspecting the Exception object created when a parsing error occurs.

Suggested solution

First, pybtex.fs_utils.import_bib_files should be refactored to store the Exception object created when a parsing error occurs instead of storing None in the dictionary it returns.

These Exception objects have a number of parameters which can be queried to determine exactly what happened to cause the parser to fail. For example:

>>> from pybtex.database.input import bibtex
>>> from pybtex.exceptions import PybtexError
>>> parser = bibtex.Parser()
>>> try:
>>>    parser.parse_file("bookshelf.bib")
>>> except PybtexError, e:
>>>    pass
>>> e.error_type
'syntax error'
>>> e.message
u'entry key expected'
>>> e.lineno
228
>>> e.get_context()
u'@Book{,\n     ^^^'

For each unparseable file, the refmanage cli should output the filename (like it does with the default behavior), then each of the items in the list above, indented with a tab.

$ ref --test --verbose bookshelf.bib
bookshelf.bib
    type: syntax error
    message: entry key expected
    line number: 228
    context: @Book{,\n     ^^^

Note

This issue is split from #32.

The above example assumes that issue #33 has not been closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant