cute-jumper / gscholar-bibtex

Retrieve BibTeX entries from Google Scholar, ACM Digital Library, IEEE Xplore and DBLP
107 stars 12 forks source link

Proposed fix for "args out of range" error in #10 and #11 #12

Open treese opened 8 years ago

treese commented 8 years ago

I also ran into the problem described in #10 and #11, and I have a proposed fix for it (see related pull request). It appears that sometimes Emacs has an old cookie for Google Scholar without the BibTeX trigger. In that case, the code tries to add an additional Cookie: header, which doesn't work because the HTTP spec only allows one, and Google doesn't process any others.

In the fix, we fabricate a cookie that is set as if it had been received from the server, with an expiration time one hour in the future. This seems to work on my system, at least (Mac OS X Yosemite, Aquamacs development version, based on Emacs 25.0.95.1), so I am submitting it for your consideration.

cute-jumper commented 8 years ago

Open for feedback :-)

vikasrawal commented 7 years ago

I still get this error.

elt([] 0) (string= "" (elt gscholar-bibtex-entries-cache index)) (if (string= "" (elt gscholar-bibtex-entries-cache index)) (progn (aset gscholar-bibtex-entries-cache index (gscholar-bibtex-dispatcher :bibtex-content (nth index gscholar-bibtex-urls-cache))))) (progn (if (string= "" (elt gscholar-bibtex-entries-cache index)) (progn (aset gscholar-bibtex-entries-cache index (gscholar-bibtex-dispatcher :bibtex-content (nth index gscholar-bibtex-urls-cache))))) (elt gscholar-bibtex-entries-cache index)) (let* ((index (gscholar-bibtex--current-index)) (bibtex-entry (progn (if (string= "" (elt gscholar-bibtex-entries-cache index)) (progn (aset gscholar-bibtex-entries-cache index (gscholar-bibtex-dispatcher :bibtex-content ...)))) (elt gscholar-bibtex-entries-cache index))) (entry-buffer (get-buffer-create gscholar-bibtex-entry-buffer-name)) (entry-window (get-buffer-window entry-buffer)) (gscholar-window (selected-window))) (save-current-buffer (set-buffer entry-buffer) (erase-buffer) (insert bibtex-entry) (bibtex-mode) (bibtex-set-dialect) (goto-char (point-min))) (if entry-window nil (select-window (split-window-below)) (switch-to-buffer entry-buffer) (select-window gscholar-window))) gscholar-bibtex-retrieve-and-show-bibtex() gscholar-bibtex--write-bibtex-to-database-impl(t) gscholar-bibtex-append-bibtex-to-database() funcall-interactively(gscholar-bibtex-append-bibtex-to-database)

(gscholar-bibtex-append-bibtex-to-database nil nil)

apply(# gscholar-bibtex-append-bibtex-to-database (nil nil)) call-interactively@ido-cr+-record-current-command(# gscholar-bibtex-append-bibtex-to-database nil nil) apply(call-interactively@ido-cr+-record-current-command # (gscholar-bibtex-append-bibtex-to-database nil nil)) call-interactively(gscholar-bibtex-append-bibtex-to-database nil nil) command-execute(gscholar-bibtex-append-bibtex-to-database)

cute-jumper commented 7 years ago

@vikasrawal Can you provide more detailed steps to reproduce the problem? Thanks!

vikasrawal commented 7 years ago
  1. emacs -Q from the terminal emulator
  2. M-x package-initialize
  3. M-: (require 'url)
  4. M-x gscholar-bibtex

M-x toggle-debug-on-error then gives this:

Debugger entered--Lisp error: (args-out-of-range [] 0) elt([] 0) (string= "" (elt gscholar-bibtex-entries-cache index)) (if (string= "" (elt gscholar-bibtex-entries-cache index)) (progn (aset gscholar-bibtex-entries-cache index (gscholar-bibtex-dispatcher :bibtex-content (nth index gscholar-bibtex-urls-cache))))) (progn (if (string= "" (elt gscholar-bibtex-entries-cache index)) (progn (aset gscholar-bibtex-entries-cache index (gscholar-bibtex-dispatcher :bibtex-content (nth index gscholar-bibtex-urls-cache))))) (elt gscholar-bibtex-entries-cache index)) (let* ((index (gscholar-bibtex--current-index)) (bibtex-entry (progn (if (string= "" (elt gscholar-bibtex-entries-cache index)) (progn (aset gscholar-bibtex-entries-cache index (gscholar-bibtex-dispatcher :bibtex-content ...)))) (elt gscholar-bibtex-entries-cache index))) (entry-buffer (get-buffer-create gscholar-bibtex-entry-buffer-name)) (entry-window (get-buffer-window entry-buffer)) (gscholar-window (selected-window))) (save-current-buffer (set-buffer entry-buffer) (erase-buffer) (insert bibtex-entry) (bibtex-mode) (bibtex-set-dialect) (goto-char (point-min))) (if entry-window nil (select-window (split-window-below)) (switch-to-buffer entry-buffer) (select-window gscholar-window))) gscholar-bibtex-retrieve-and-show-bibtex() gscholar-bibtex--write-bibtex-to-database-impl(t) gscholar-bibtex-append-bibtex-to-database() funcall-interactively(gscholar-bibtex-append-bibtex-to-database)

(gscholar-bibtex-append-bibtex-to-database nil nil)

apply(# gscholar-bibtex-append-bibtex-to-database (nil nil)) call-interactively@ido-cr+-record-current-command(# gscholar-bibtex-append-bibtex-to-database nil nil) apply(call-interactively@ido-cr+-record-current-command # (gscholar-bibtex-append-bibtex-to-database nil nil)) call-interactively(gscholar-bibtex-append-bibtex-to-database nil nil) command-execute(gscholar-bibtex-append-bibtex-to-database)

On 27-Oct-2017, at 10:17 PM, Junpeng Qiu notifications@github.com wrote:

@vikasrawal Can you provide more detailed steps to reproduce the problem? Thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

cute-jumper commented 7 years ago

@vikasrawal You don't have any input?

vikasrawal commented 7 years ago

I selected Google Scholar as the source, searched for “Prabhat Patnaik”, and got the results in a buffer.

But when I do A, W, a, w, or c, I only get: string=: Args out of range: [], 0

On 28-Oct-2017, at 8:53 AM, Junpeng Qiu notifications@github.com wrote:

@vikasrawal https://github.com/vikasrawal You don't have any input?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cute-jumper/gscholar-bibtex/issues/12#issuecomment-340135799, or mute the thread https://github.com/notifications/unsubscribe-auth/AAdRzCFWFkolTXZT8_yU9986ejXHfAaxks5swp4igaJpZM4I_n6r.

cute-jumper commented 7 years ago

@vikasrawal Sorry. I'm unable to reproduce the problem. It works fine on my side. My guess is that it is probably caused by the network issues you may have when accessing Google Scholar. Are you familiar elisp? Try edebug on the gscholar-bibtex command and see whether the variable gscholar-bibtex-urls-cache has been set successfully or not.