magit/ghub

Error in ghub-get

Closed this issue · 5 comments

  • Emacs 29.0.92
  • macOS 13.4
  • ghub-20230513.1619
(require 'ghub)
(ghub-get "/notifications" nil
          :query '((notifications . "true"))
          :username [user]
          :auth [token]
          :unpaginate t)

When I use the snippet above to get the notifications from GitHub, I got this error:

Debugger entered--Lisp error: (error "Invalid search bound (wrong side of point)")
  #<subr re-search-forward>("^\\([^:]*\\): \\(.+\\)" #<marker at 1 in  *http api.github.com:443*> t nil)
  re-search-forward("^\\([^:]*\\): \\(.+\\)" #<marker at 1 in  *http api.github.com:443*> t)
  ghub--handle-response-headers((:peer (:certificates ((:version 3 :serial-number "0b:89:05:37:12:5f:45:10:d6:37:2a:10:28:a9:29:a5" :issuer "C=US,O=DigiCert Inc,CN=DigiCert TLS Hybrid ECC SHA..." :valid-from "2023-02-16" :valid-to "2024-03-15" :subject "C=US,ST=California,L=San Francisco,O=GitHub\\, Inc...." :public-key-algorithm "EC/ECDSA" :certificate-security-level "High" :signature-algorithm "ECDSA-SHA384" :public-key-id "sha1:b6:3f:03:4b:19:b5:09:31:ad:35:c2:7b:0c:10:5b:..." :certificate-id "sha1:2d:79:6c:90:2d:ad:8a:2e:4f:d1:e2:99:ed:e8:91:..." :pem "-----BEGIN CERTIFICATE-----\nMIIFaTCCBO+gAwIBAgIQC4...") (:version 3 :serial-number "07:f2:f3:5c:87:a8:77:af:7a:ef:e9:47:99:35:25:bd" :issuer "C=US,O=DigiCert Inc,OU=www.digicert.com,CN=DigiCer..." :valid-from "2021-04-14" :valid-to "2031-04-13" :subject "C=US,O=DigiCert Inc,CN=DigiCert TLS Hybrid ECC SHA..." :public-key-algorithm "EC/ECDSA" :certificate-security-level "Ultra" :signature-algorithm "RSA-SHA384" :public-key-id "sha1:3f:a4:c2:7e:9c:9c:89:2c:6b:98:6c:1c:3e:1f:40:..." :certificate-id "sha1:ae:c1:3c:dd:5e:a6:a3:99:8a:ec:14:ac:33:1a:d9:..." :pem "-----BEGIN CERTIFICATE-----\nMIIEFzCCAv+gAwIBAgIQB/...")) :certificate (:version 3 :serial-number "0b:89:05:37:12:5f:45:10:d6:37:2a:10:28:a9:29:a5" :issuer "C=US,O=DigiCert Inc,CN=DigiCert TLS Hybrid ECC SHA..." :valid-from "2023-02-16" :valid-to "2024-03-15" :subject "C=US,ST=California,L=San Francisco,O=GitHub\\, Inc...." :public-key-algorithm "EC/ECDSA" :certificate-security-level "High" :signature-algorithm "ECDSA-SHA384" :public-key-id "sha1:b6:3f:03:4b:19:b5:09:31:ad:35:c2:7b:0c:10:5b:..." :certificate-id "sha1:2d:79:6c:90:2d:ad:8a:2e:4f:d1:e2:99:ed:e8:91:..." :pem "-----BEGIN CERTIFICATE-----\nMIIFaTCCBO+gAwIBAgIQC4...") :key-exchange "ECDHE-RSA" :protocol "TLS1.3" :cipher "AES-128-GCM" :mac "AEAD" :encrypt-then-mac nil)) #s(ghub--req :url #s(url :type "https" :user nil :password nil :host "api.github.com" :portspec nil :filename "/notifications?notifications=true" :target nil :attributes nil :fullness t :silent nil :use-cookies t :asynchronous nil) :forge nil :silent nil :method "GET" :headers #f(compiled-function () #<bytecode 0x5a24ed9ae4e6d89>) :handler ghub--handle-response :unpaginate t :noerror t :reader nil :callback nil :errorback nil :value nil :extra nil))
  ghub--handle-response((:peer (:certificates ((:version 3 :serial-number "0b:89:05:37:12:5f:45:10:d6:37:2a:10:28:a9:29:a5" :issuer "C=US,O=DigiCert Inc,CN=DigiCert TLS Hybrid ECC SHA..." :valid-from "2023-02-16" :valid-to "2024-03-15" :subject "C=US,ST=California,L=San Francisco,O=GitHub\\, Inc...." :public-key-algorithm "EC/ECDSA" :certificate-security-level "High" :signature-algorithm "ECDSA-SHA384" :public-key-id "sha1:b6:3f:03:4b:19:b5:09:31:ad:35:c2:7b:0c:10:5b:..." :certificate-id "sha1:2d:79:6c:90:2d:ad:8a:2e:4f:d1:e2:99:ed:e8:91:..." :pem "-----BEGIN CERTIFICATE-----\nMIIFaTCCBO+gAwIBAgIQC4...") (:version 3 :serial-number "07:f2:f3:5c:87:a8:77:af:7a:ef:e9:47:99:35:25:bd" :issuer "C=US,O=DigiCert Inc,OU=www.digicert.com,CN=DigiCer..." :valid-from "2021-04-14" :valid-to "2031-04-13" :subject "C=US,O=DigiCert Inc,CN=DigiCert TLS Hybrid ECC SHA..." :public-key-algorithm "EC/ECDSA" :certificate-security-level "Ultra" :signature-algorithm "RSA-SHA384" :public-key-id "sha1:3f:a4:c2:7e:9c:9c:89:2c:6b:98:6c:1c:3e:1f:40:..." :certificate-id "sha1:ae:c1:3c:dd:5e:a6:a3:99:8a:ec:14:ac:33:1a:d9:..." :pem "-----BEGIN CERTIFICATE-----\nMIIEFzCCAv+gAwIBAgIQB/...")) :certificate (:version 3 :serial-number "0b:89:05:37:12:5f:45:10:d6:37:2a:10:28:a9:29:a5" :issuer "C=US,O=DigiCert Inc,CN=DigiCert TLS Hybrid ECC SHA..." :valid-from "2023-02-16" :valid-to "2024-03-15" :subject "C=US,ST=California,L=San Francisco,O=GitHub\\, Inc...." :public-key-algorithm "EC/ECDSA" :certificate-security-level "High" :signature-algorithm "ECDSA-SHA384" :public-key-id "sha1:b6:3f:03:4b:19:b5:09:31:ad:35:c2:7b:0c:10:5b:..." :certificate-id "sha1:2d:79:6c:90:2d:ad:8a:2e:4f:d1:e2:99:ed:e8:91:..." :pem "-----BEGIN CERTIFICATE-----\nMIIFaTCCBO+gAwIBAgIQC4...") :key-exchange "ECDHE-RSA" :protocol "TLS1.3" :cipher "AES-128-GCM" :mac "AEAD" :encrypt-then-mac nil)) #s(ghub--req :url #s(url :type "https" :user nil :password nil :host "api.github.com" :portspec nil :filename "/notifications?notifications=true" :target nil :attributes nil :fullness t :silent nil :use-cookies t :asynchronous nil) :forge nil :silent nil :method "GET" :headers #f(compiled-function () #<bytecode 0x5a24ed9ae4e6d89>) :handler ghub--handle-response :unpaginate t :noerror t :reader nil :callback nil :errorback nil :value nil :extra nil))
  ghub--retrieve(nil #s(ghub--req :url #s(url :type "https" :user nil :password nil :host "api.github.com" :portspec nil :filename "/notifications?notifications=true" :target nil :attributes nil :fullness t :silent nil :use-cookies t :asynchronous nil) :forge nil :silent nil :method "GET" :headers #f(compiled-function () #<bytecode 0x5a24ed9ae4e6d89>) :handler ghub--handle-response :unpaginate t :noerror t :reader nil :callback nil :errorback nil :value nil :extra nil))
  ghub-request("GET" "/notifications" nil :query ((notifications . "true")) :payload nil :headers nil :silent nil :unpaginate t :noerror t :reader nil :username "seagle0128" :auth ghub :host nil :callback nil :errorback nil :extra nil)
  ghub-get("/notifications" nil :query ((notifications . "true")) :username "seagle0128" :auth ghub :unpaginate t :noerror t)
  (progn (defvar embark--target-mode-string) (defvar embark--target-mode-timer) (ghub-get "/notifications" nil :query '((notifications . "true")) :username "seagle0128" :auth 'ghub :unpaginate t :noerror t))
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  #<subr command-execute>(eval-last-sexp nil nil nil)
  ad-Advice-command-execute(#<subr command-execute> eval-last-sexp)
  apply(ad-Advice-command-execute #<subr command-execute> eval-last-sexp)
  command-execute(eval-last-sexp)

That's what forge does:

(ghub-get "/notifications"
          '((all . t)) ;well nil actually, but since I have already read all, that would return nothing
          :auth 'forge
          :host "api.github.com"
          :unpaginate nil) ;well t actually, but lets speed things up

Of course depending on what key you used to store the token, you might have to change :auth and/or provide :username explicitly (see docstring of ghub-request).

Actually the second evaluation returned the errors. The first one works well.

Actually the second evaluation returned the errors. The first one works well.

You evaluated the same code (which you have posted above) twice, and the first time it worked and the second time it resulted in the backtrace you posted above?

@tarsius Yes. What was I missing?

First, let's get some side issue out of the way:

  1. Whether one uses the PARAMS argument as I have done above, or QUERY as you have, makes no difference.
  2. Encode the boolean true value as t, not "true", though the latter also works.
  3. I have to assume the values you provided for USERNAME and AUTH are correct.
  4. I am now also using t for UNPAGINATE, because even then it isn't that much data.
  5. You set the parameter notification to true. Such a parameter does not exist, see: https://docs.github.com/en/rest/activity/notifications?apiVersion=2022-11-28#list-notifications-for-the-authenticated-user--parameters. It is possible that the problem was that the use of that parameter lead to an error that the ghub code was not prepared to handle. But try again, I just did, and for me this invalid parameter was just silently ignored.

I still can evaluate the below, even repeatably, and it always returns the expected data and never errors.

(ghub-get "/notifications" '((all . t)) :unpaginate t)

If you can reproduce the issue, you will have to investigate it yourself. I will close until then, because I currently think there isn't actually an issue in Ghub.