zotero / citeproc-rs

CSL processor in Rust.

Home Page:https://cormacrelf.github.io/citeproc-wasm-demo/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fatal failure with unexpected page field data

adomasven opened this issue · comments

I've been testing over a bunch of old documents and ran into this error:

(5)(+0000001): CiteprocRs: batchedUpdates

(3)(+0000064): RuntimeError: unreachable executed __rust_start_panic@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:3933323:1 rust_panic@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:3917250:1 std::panicking::rust_panic_with_hook::h5395f3796c27894a@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:3743951:1 rust_begin_unwind@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:3904279:1 core::panicking::panic_fmt::h0dbc4ba05c77baa3@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:3913562:1 core::option::expect_none_failed::h126917f90cba260e@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:3850499:1 citeproc_io::numeric::num_alpha_num::{{closure}}::hb9a26a06ae1f77c7@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:3273116:1 citeproc_io::numeric::num_ish::hcc38c1239e41e686@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:1548126:1 citeproc_io::numeric::NumericValue::parse_full::hddf12232ec0098c2@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:991784:1 <citeproc_proc::cite_context::CiteContext<O,I> as citeproc_proc::cite_context::RenderContext>::get_number::{{closure}}::h2ee896cefcacb999@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:3109807:1 <citeproc_proc::cite_context::CiteContext<O,I> as citeproc_proc::cite_context::RenderContext>::get_number::h3666ad58bc2f04d8@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:2751870:1 citeproc_proc::IrState::maybe_suppress_num::he0418788d31c7174@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:3308652:1 citeproc_proc::element::<impl citeproc_proc::Proc<O,I> for csl::style::Element>::intermediate::h654e1790b9109a05@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:752345:1 citeproc_proc::helpers::sequence::hf5cd23065843b10f@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:1555607:1 citeproc_proc::choose::eval_ifthen::h3e556c3c7307cb3a@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:3174782:1 citeproc_proc::choose::<impl citeproc_proc::Proc<O,I> for alloc::sync::Arc<csl::style::Choose>>::intermediate::hc6c50d568ff74573@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:2393448:1 citeproc_proc::element::<impl citeproc_proc::Proc<O,I> for csl::style::Element>::intermediate::h654e1790b9109a05@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:749498:1 citeproc_proc::helpers::sequence::hf5cd23065843b10f@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:1555607:1 citeproc_proc::choose::eval_ifthen::h3e556c3c7307cb3a@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:3174782:1 citeproc_proc::choose::<impl citeproc_proc::Proc<O,I> for alloc::sync::Arc<csl::style::Choose>>::intermediate::hc6c50d568ff74573@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:2393547:1 citeproc_proc::element::<impl citeproc_proc::Proc<O,I> for csl::style::Element>::intermediate::h654e1790b9109a05@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:749498:1 citeproc_proc::helpers::sequence::hf5cd23065843b10f@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:1555607:1 citeproc_proc::element::<impl citeproc_proc::Proc<O,I> for csl::style::Element>::intermediate::h654e1790b9109a05@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:750038:1 citeproc_proc::helpers::sequence::hf5cd23065843b10f@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:1555607:1 <citeproc_proc::db::BibItemGen0Query as salsa::plumbing::QueryFunction>::execute::h0a2abac69d418a40@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:1224620:1 salsa::derived::slot::Slot<Q,MP>::read_upgrade::h71df57abfbc896c9@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:821526:1 salsa::derived::slot::Slot<Q,MP>::read::h5b8b842cd71d460b@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:2197295:1 <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch::ha57240a80a52e291@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:2328520:1 <DB as citeproc_proc::db::IrDatabase>::bib_item_gen0::__shim::hc8ed9cf4992c0e3a@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:3751760:1 <DB as citeproc_proc::db::IrDatabase>::bib_item_gen0::hb264632af3b048ef@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:3927691:1 <citeproc_proc::db::GetBibliographyMapQuery as salsa::plumbing::QueryFunction>::execute::hcc682aa18a4c463d@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:1585313:1 salsa::derived::slot::Slot<Q,MP>::read_upgrade::h61ba2c3083cc2262@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:919158:1 salsa::derived::slot::Slot<Q,MP>::read::h06730e013776937a@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:2237650:1 <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch::hbf9b37acc0597448@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:1955556:1 <DB as citeproc_proc::db::IrDatabase>::get_bibliography_map::__shim::hac9c8f6bdae9dd38@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:3834967:1 citeproc::processor::Processor::save_and_diff_bibliography::h3dd633c777c169a3@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:1665750:1 citeproc::processor::Processor::batched_updates_str::h4989718f8bd964af@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:2561629:1 wasm::Driver::batched_updates::hf6c10ea98b5fba46@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:2486921:1 driver_batchedUpdates@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:3851268:1 batchedUpdates@resource://zotero/loader.jsm -> resource://zotero/citeproc_rs_wasm.js:415:19 getBatchedUpdates@chrome://zotero/content/xpcom/citeproc-rs-to-citeproc-js.js:156:14 Zotero.Integration.Session.prototype._updateCitationsCiteprocRs@chrome://zotero/content/xpcom/integration.js:1895:25 Zotero.Integration.Session.prototype._updateCitations@chrome://zotero/content/xpcom/integration.js:1817:12 Zotero.Integration.Fields.prototype.updateDocument<@chrome://zotero/content/xpcom/integration.js:992:9 tryCatcher@resource://zotero/loader.jsm -> resource://zotero/bluebird/util.js:16:16 module.exports/PromiseSpawn.prototype._promiseFulfilled@resource://zotero/loader.jsm -> resource://zotero/bluebird/generators.js:97:18 From previous event: captureStackTrace@resource://zotero/loader.jsm -> resource://zotero/bluebird/debuggability.js:915:23 CapturedTrace@resource://zotero/loader.jsm -> resource://zotero/bluebird/debuggability.js:807:5 longStackTracesCaptureStackTrace@resource://zotero/loader.jsm -> resource://zotero/bluebird/debuggability.js:482:19 module.exports/Promise.prototype._then@resource://zotero/loader.jsm -> resource://zotero/bluebird/promise.js:261:9 module.exports/Promise.prototype._passThrough@resource://zotero/loader.jsm -> resource://zotero/bluebird/finally.js:94:12 module.exports/Promise.prototype.finally@resource://zotero/loader.jsm -> resource://zotero/bluebird/finally.js:103:12 PromiseSpawn@resource://zotero/loader.jsm -> resource://zotero/bluebird/generators.js:36:25 module.exports/Promise.coroutine/<@resource://zotero/loader.jsm -> resource://zotero/bluebird/generators.js:197:21 Zotero.Integration.Interface.prototype.refresh@chrome://zotero/content/xpcom/integration.js:699:9

I isolated the problematic citation and it appears to have crazy data for the item page:

{"citationID":"UkVQybLi","properties":{"formattedCitation":"(Hamre et al. 2007)","plainCitation":"(Hamre et al. 2007)","noteIndex":0},"citationItems":[{"id":"5IR1ctXb/qmHPArzD","uris":["http://zotero.org/users/807735/items/SVSN2WHW"],"itemData":{"id":445,"type":"article-journal","title":"Teachers' Perceptions of Conflict with Young Students: Looking beyond Problem Behaviors","container-title":"Social Development","page":"071124114012001-???","volume":"0","issue":"0","source":"CrossRef","DOI":"10.1111/j.1467-9507.2007.00418.x","ISSN":"0961-205X, 1467-9507","language":"en","author":[{"family":"Hamre","given":"Bridget K."},{"family":"Pianta","given":"Robert C."},{"family":"Downer","given":"Jason T."},{"family":"Mashburn","given":"Andrew J."}],"issued":{"date-parts":[["2007",11,22]]},"title-short":"Teachers' Perceptions of Conflict with Young Students"}}],"schema":"https://github.com/citation-style-language/schema/raw/master/csl-citation.json"}

citeproc-js deals with this by simply ignoring the field. I have no idea how that page value got like that, it's from a document that i have from way back, but it's not impossible that this was the result of a translator save from some journal where the served item metadata was like that. Either way, citeproc-rs shouldn't fail for something like this. Moreover, the driver instance got busted after that and further calls to insertReference() would fail with a similar error (I presume if I'd call setClusterOrder first and removed that reference maybe it would fix itself.

Right, so specifically this is both an integer overflow, and then the panic message not showing up, which might (similarly to #92 and the logging discussion) be because it attempts to log it with window.console.error and can't. From pasting it in a locator in the demo page:

panicked at 'must parse digit1: ParseIntError { kind: Overflow }', crates/io/src/numeric.rs:306:26

The fix is that citeproc-rs should notice that str::parse::<u32>() failed and rather than unwrap/panic it, deal with it by having it be non-numeric. Better than ignoring, I think. I'll get on that.


For some discussion of what panics mean for you in general, I can't make it so panics are recoverable. They're not normal errors, they're not in fact meant to ever happen at all, they're programmer errors not user errors, and they involve the Rust call stack completely unwinding itself and cleaning up as it goes, so there's half-written data in there that wouldn't make sense to recover from. The correct thing to do is have me audit all the places in the program where it can do this, which isn't many. In code though: stop using driver instance, attempt to free() it in a try block, display error, report bug, that's all you can do.

If you really wanted to, you should be able to catch this kind of disastrous case once #94 is merged: catch(e) { if (!(e instanceof CiteprocRsError)) { ... } } which means I didn't create the error myself. The difference is that CiteprocRsErrors are all technically recoverable -- you can definitely keep using the driver -- as well as some of them being conceptually recoverable -- you could fix a typo in the style. Whereas any other kind of error is blowing up.