crsh / citr

RStudio Addin to Insert Markdown Citations
Other
407 stars 46 forks source link

citr crashes connecting to Zotero library #74

Open earcanal opened 3 years ago

earcanal commented 3 years ago

Describe the bug

citr crashes when connecting to Zotero library.

To Reproduce

  1. Click Connect and load libraries, next to Zotero connection available.

Console displays error message below, and R Studio requires a restart to prevent this error when accessing citr.

> citr:::insert_citation()

Unsaved R Markdown document: Cannot locate bibliography files;
         falling back to manual path specification.

Listening on http://127.0.0.1:5619
Warning in do_read_bib(file, encoding = .Encoding, srcfile) :

Mtvgyl61J71EobVglxMuYlmwMCnmKQI6.bib:2:0
    syntax error, unexpected $end
    Dropping the entry `Lottridge2012` (starting at line 55) 
Warning: Error in do_read_bib: unprotect_ptr: pointer not found
  70: do_read_bib
  69: RefManageR::ReadBib
  68: import_bbt
  67: load_betterbiblatex_bib
  63: <reactive>
  47: bibliography
  46: <observer>
   3: shiny::runApp
   2: runGadget
   1: citr:::insert_citation
Warning: Error in do_read_bib: unprotect_ptr: pointer not found
  49: <Anonymous>
Warning: Error in do_read_bib: unprotect_ptr: pointer not found

Expected behavior

Able to cite items in Zotero library.

Screenshots

citr

earcanal commented 3 years ago

This looks like a dup of #71, and could be an instance of a known issue. I get a similar error (with a different key) after adding 'abstract' to Fields to omit from export in Better BibTeX config.

> citr:::insert_citation()

Listening on http://127.0.0.1:4729
Warning in do_read_bib(file, encoding = .Encoding, srcfile) :

qRaBLTQp0Bfju6Mu3eSCYfvRYQgb65CT.bib:2:0
    syntax error, unexpected $end
    Dropping the entry `baer2019` (starting at line 2373) 
Warning: Error in do_read_bib: unprotect_ptr: pointer not found
  70: do_read_bib
  69: RefManageR::ReadBib
  68: import_bbt
  67: load_betterbiblatex_bib
  63: <reactive>
  47: bibliography
  46: <observer>
   3: shiny::runApp
   2: runGadget
   1: citr:::insert_citation
Warning: Error in do_read_bib: unprotect_ptr: pointer not found
  49: <Anonymous>
Warning: Error in do_read_bib: unprotect_ptr: pointer not found
  106: <Anonymous>
earcanal commented 3 years ago

Fields to omit from export = abstract,notes doesn't resolve the issue.

I've established that the citation key in the syntax error message is the last one in the configured .bib, regardless of how many entries there are in that file. If it's empty, it says null. I suspect this error is a red herring.

I wonder if there's a memory overflow due to the size of my Zotero libraries. If I've counted correctly, the total number of items in my libraries is just over 4,000. You could test this hypothesis by starting with a library size that doesn't produce the error, then repeatedly duplicating all of the items, to see if you can reproduce it.

earcanal commented 3 years ago

Hmm, I didn't think I'd made any changes, but citr can now load the Zotero libraries! So it looks like omitting abstract,notes resolved this for me.

However, I still have some errors, and citr can't find the item in a Zotero library that I want to cite:

> citr:::insert_citation()

Listening on http://127.0.0.1:7262
Warning in do_read_bib(file, encoding = .Encoding, srcfile) :

uYOdyFJIkKBEZDxxnDqKsPdqGEwFbkUU.bib:27507:0
    syntax error, unexpected TOKEN_AT, expecting TOKEN_COMMA or TOKEN_RBRACE
    Dropping the entry `spitzerrlBriefMeasureAssessing2006` (starting at line 27488) 
Ignoring entry ‘buehlerPlanningFallacyCauses2002’ (line3865) because: 
    The name list field author cannot be parsed

Warning in do_read_bib(file, encoding = .Encoding, srcfile) :

johR9DIacJyuQ9n1FB8hCjTBrEzbEoYD.bib:9:1
    syntax error, unexpected TOKEN_VALUE, expecting TOKEN_LBRACE
    Dropping the entry `spitzerrlBriefMeasureAssessing2006` (starting at line 27488) 
Warning in do_read_bib(file, encoding = .Encoding, srcfile) :

ly3yjrICAfFABmfAON2B63uBUQYaMEXj.bib:5:1
    syntax error, unexpected TOKEN_VALUE, expecting TOKEN_LBRACE
    Dropping the entry `spitzerrlBriefMeasureAssessing2006` (starting at line 27488) 
Warning in do_read_bib(file, encoding = .Encoding, srcfile) :

PHBCMemrIp1bPQeQ9HUyshFYyOyFUBqx.bib:7:1
    syntax error, unexpected TOKEN_VALUE, expecting TOKEN_LBRACE
    Dropping the entry `spitzerrlBriefMeasureAssessing2006` (starting at line 27488) 
Warning: stack imbalance in '<-', 301 then 315
Warning: stack imbalance in '{', 297 then 311
Warning: stack imbalance in '{', 287 then 301
Warning: stack imbalance in 'if', 285 then 299
Warning: stack imbalance in '{', 281 then 295
Warning: stack imbalance in 'if', 279 then 293
Warning: stack imbalance in '{', 275 then 289
Warning: stack imbalance in 'if', 273 then 287
Warning: stack imbalance in '{', 269 then 283
Warning: stack imbalance in 'if', 260 then 274
Warning: stack imbalance in '{', 256 then 270
Warning: stack imbalance in 'withVisible', 250 then 264
Warning: stack imbalance in '{', 244 then 258
Warning: stack imbalance in '<-', 238 then 252
Warning: stack imbalance in '{', 234 then 248
Warning: stack imbalance in '{', 227 then 241
Warning: stack imbalance in '{', 220 then 234
Warning: stack imbalance in '{', 206 then 220
Warning: stack imbalance in '{', 196 then 210
Warning: stack imbalance in '{', 189 then 203
Warning: stack imbalance in '{', 178 then 192
Warning: stack imbalance in 'if', 176 then 190
Warning: stack imbalance in '{', 172 then 186
Warning: stack imbalance in 'names', 168 then 182
Warning: stack imbalance in '<-', 166 then 180
Warning: stack imbalance in '{', 162 then 176
Warning: stack imbalance in 'if', 153 then 167
Warning: stack imbalance in '{', 149 then 163
Warning: stack imbalance in '{', 142 then 156
Warning: stack imbalance in '{', 135 then 149
Warning: stack imbalance in '{', 121 then 135
Warning: stack imbalance in '{', 111 then 125
Warning: stack imbalance in '{', 104 then 118
Warning: stack imbalance in '{', 83 then 97
Warning: stack imbalance in 'if', 81 then 95
Warning: stack imbalance in '{', 77 then 91
Warning: stack imbalance in 'withVisible', 71 then 85
earcanal commented 3 years ago

Mystically, after another R Studio restart, that error goes away too, and I can cite the item I wanted! So this is resolved, I'm just not sure how!

crsh commented 3 years ago

Thanks for reaching out and reporting on your progress. I'm not sure exactly what went wrong here, but omitting abstract and note and restarting the R session once you encounter such errors has helped to fix these types of errors before. I have been unsatisfied with the approach to interface with Zotero, so I've been looking for an alternative. But seeing that the next RStudio release will feature a visual editor for R Markdown that comes with a built-in citation feature and connects to Zotero, I may halt development on citr (unless it get's picked up by VSCode users).

earcanal commented 3 years ago

Please don't give up yet! I came back to citr after deciding that the visual editor isn't production quality yet. Notably inserting square brackets around citations is a showstopper. Also, I prefer writing in markdown, and although good, the citation features are only available in the visual editor.

crsh commented 3 years ago

Thanks for the feedback. I'll keep an open mind about it.

earcanal commented 3 years ago

I'm reopening this, as the behaviour is intermittent. When it works, the connection to Zotero is made when you first open citr. If that doesn't happen and you have to click Connect and load libraries, then it triggers the bug.

I can't explain why the connection to Zotero is intermittently made when opening citr.

ShixiangWang commented 3 years ago

Still crash with the latest version from GitHub, any updates?

krzyklo commented 2 years ago

I have also R Studio crash, when trying to link and connect Zotero library.

citr:::insert_citation()

Listening on http://127.0.0.1:7856 Warning: Error in bibtex::do_read_bib: lex fatal error: fatal flex scanner internal error--end of buffer missed

70: bibtex::do_read_bib 69: RefManageR::ReadBib 68: import_bbt 67: load_betterbiblatex_bib 63: 47: bibliography 46: 3: shiny::runApp 2: runGadget 1: citr:::insert_citation Warning: Error in bibtex::do_read_bib: lex fatal error: fatal flex scanner internal error--end of buffer missed

49: Warning: Error in bibtex::do_read_bib: lex fatal error: fatal flex scanner internal error--end of buffer missed

106:

krzyklo commented 2 years ago

Though, I could export whole database to BIB file with Zotero -> Preferences -> Automatic export to File.

Then could manually put references into Rmd documents, which are found when Knitting. This basicly bypass, CITR completely.

KK