larsgw / citation.js

Citation.js converts formats like BibTeX, Wikidata JSON and ContentMine JSON to CSL-JSON to convert to other formats like APA, Vancouver and back to BibTeX.
https://citation.js.org/
MIT License
222 stars 30 forks source link

Try/Catch Cite.Add() not throwing error forward #173

Closed thelunararmy closed 5 years ago

thelunararmy commented 5 years ago

Hi there,

Would it be possible to have the Cite.add function throw the error forward when encountering a Syntax error, rather than printing the error and then fail quietly?

Would be really nice to allow the the front end to report the entire faulty entry as opposed to just displaying the syntax error without content.

i.e.

let citer = new Cite();
for (let i = 0; i < listOfEntries; i++){
   try {
        await citer.addAsync(listOfEntries[i], {}, true);
    } catch (err) {
        // Handle using ui element
    }
} 

Currently this catch never triggers.

EternalDeiwos commented 5 years ago

Should be noted that the error in question comes from trying to parse bibtex records such as this:

@article{citekey,
  ...
  author={Garc{\'\i}a-Molina, H{\'e}ctor},
  ...
}

This was taken from Google Scholar and fails (like many others) with a syntax error because {\'\i} is "not a valid escape sequence".

larsgw commented 5 years ago

@thelunararmy I've been wanting to do something like that for a while now, including cutting down on other unnecessary log messages. It's a pretty breaking change, but I guess I can put it behind an input option for now. See #130.

@EternalDeiwos That definitely seems like syntax that should be supported, and either way, I agree "not a valid escape sequence" should be more like "unknown escape sequence".

BTW: I am planning to do these things in a week or two.

EternalDeiwos commented 5 years ago

@larsgw Thanks. Looking forward to it.

larsgw commented 5 years ago

Some deadlines are getting in the way, about one more week I think.

thelunararmy commented 5 years ago

@larsgw No problem, thank you for the feedback! Much appreciated.