Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fails to deal with invalid oauth tokens #49

Open
aspiers opened this issue Sep 18, 2015 · 0 comments
Open

fails to deal with invalid oauth tokens #49

aspiers opened this issue Sep 18, 2015 · 0 comments
Assignees
Milestone

Comments

@aspiers
Copy link

aspiers commented Sep 18, 2015

This is a different issue to #38. If an invalid oauth token is used, you get the very cryptic error:

if: Wrong type argument: listp, "https://developer.github.com/v3"

For some reason setting debug-on-error and debug-on-signal both to t didn't help obtain a backtrace of this, so not knowing any better way, I had to spend several hours with Edebug and macrostep before tracking it down. The HTTP response body is:

{"message":"Bad credentials","documentation_url":"https://developer.github.com/v3"}

gh-url-response-init obtains the HTTP response status code (401) but then ignores the fact that the API call failed, and ploughs on regardless, invoking gh-url-response-set-data in a vain attempt to parse the response via gh-object-read-into. In the case where the bug was triggered via magit-gh-pulls-reload, this results in (gh-read data 'url) being evaluated where data is (documentation_url . "https://developer.github.com/v3"), which is not a list; hence the listp failure. However, the error is caught by the condition-case in gh-url-set-response, which made it a lot harder to pin down the real cause:

Debugger entered--Lisp error: (wrong-type-argument listp "https://developer.github.com/v3")
  signal(wrong-type-argument (listp "https://developer.github.com/v3"))
  (if (or (null num) (zerop num)) (signal (car err) (cdr err)) (eieio-oset req (quote :num-retries) (1- num)) (gh-url-run-request req resp))
  (let ((num (eieio-oref req (quote :num-retries)))) (if (or (null num) (zerop num)) (signal (car err) (cdr err)) (eieio-oset req (quote :num-retries) (1- num)) (gh-url-run-request req resp)))
  (condition-case err (progn (eieio-oset resp (quote :-req) req) (gh-url-response-init resp (current-buffer))) (error (let ((num (eieio-oref req (quote :num-retries)))) (if (or (null num) (zerop num)) (signal (car err) (cdr err)) (eieio-oset req (quote :num-retries) (1- num)) (gh-url-run-request req resp)))))
  (let* ((--cl-rest-- req-resp) (req (if (= (length --cl-rest--) 2) (car-safe (prog1 --cl-rest-- (setq --cl-rest-- (cdr --cl-rest--)))) (signal (quote wrong-number-of-arguments) (list nil (length --cl-rest--))))) (resp (car --cl-rest--))) (condition-case err (progn (eieio-oset resp (quote :-req) req) (gh-url-response-init resp (current-buffer))) (error (let ((num (eieio-oref req (quote :num-retries)))) (if (or (null num) (zerop num)) (signal (car err) (cdr err)) (eieio-oset req (quote :num-retries) (1- num)) (gh-url-run-request req resp))))))
  (progn (let* ((--cl-rest-- req-resp) (req (if (= (length --cl-rest--) 2) (car-safe (prog1 --cl-rest-- (setq --cl-rest-- ...))) (signal (quote wrong-number-of-arguments) (list nil (length --cl-rest--))))) (resp (car --cl-rest--))) (condition-case err (progn (eieio-oset resp (quote :-req) req) (gh-url-response-init resp (current-buffer))) (error (let ((num (eieio-oref req ...))) (if (or (null num) (zerop num)) (signal (car err) (cdr err)) (eieio-oset req (quote :num-retries) (1- num)) (gh-url-run-request req resp)))))))
  gh-url-set-response(nil ([object gh-api-paged-request "gh-api-paged-request" "GET" "https://api.github.com/repos/sigma/gh.el/pulls" nil (("Authorization" . "token <CENSORED>") ("Content-Type" . "application/json")) "null" nil 0 nil] [object gh-api-paged-response "gh-api-paged-response" nil nil (("X-Content-Type-Options" . "nosniff") ("Strict-Transport-Security" . "max-age=31536000; includeSubdomains; preload") ("X-GitHub-Request-Id" . "510267F3:19B11:69AF2F7:55FB63E5") ("Access-Control-Allow-Origin" . "*") ("Access-Control-Expose-Headers" . "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval") ("Access-Control-Allow-Credentials" . "true") ("Content-Security-Policy" . "default-src 'none'") ("X-Frame-Options" . "deny") ("X-XSS-Protection" . "1; mode=block") ("X-RateLimit-Reset" . "1442539294") ("X-RateLimit-Remaining" . "57") ("X-RateLimit-Limit" . "60") ("X-GitHub-Media-Type" . "github.v3") ("Status" . "401 Unauthorized") ("Content-Length" . "83") ("Content-Type" . "application/json; charset=utf-8") ("Date" . "Fri, 18 Sep 2015 01:07:49 GMT") ("Server" . "GitHub.com") (status-string . "Unauthorized") (status-code . "401") (status-version . "1.1")) 401 nil (closure (t) (&rest args) (apply (quote gh-object-list-read) (quote gh-pulls-request) args)) [object gh-api-paged-request "gh-api-paged-request" "GET" "https://api.github.com/repos/sigma/gh.el/pulls" nil (("Authorization" . "token <CENSORED>") ("Content-Type" . "application/json")) "null" nil 0 nil]]))
  #[(req &optional resp) "\306\307\310�\311\"\310�\312\"\310�\313\"\310�\314\"\310�\315\"\211�\203!�\316    !\202\"�\317)P��������\310�\320\"\203\\���\206>�\321\310�\322\"!�����D��r\323\n\324��C#q\210\325\326!\210����+\202|���\206g�\321\310�\322\"!�����D��r\327\n!q\210\324\330��\"\210+.�\331\332\310�\333\"\"\210��\207" [req params url url-request-extra-headers url-request-data url-request-method (("basic" ignore . 4)) high eieio-oref :method :data :headers :url :query gh-url-params-encode "" :async make-instance default-response-cls url-retrieve gh-url-set-response make-local-variable url-registered-auth-schemes url-retrieve-synchronously nil mapc #[(cb) "\302�   \"\207" [resp cb gh-url-add-response-callback] 3] :install-callbacks url-privacy-level resp req-resp] 10]([object gh-api-paged-request "gh-api-paged-request" "GET" "https://api.github.com/repos/sigma/gh.el/pulls" nil (("Authorization" . "token <CENSORED>") ("Content-Type" . "application/json")) "null" nil 0 nil] [object gh-api-paged-response "gh-api-paged-response" nil nil (("X-Content-Type-Options" . "nosniff") ("Strict-Transport-Security" . "max-age=31536000; includeSubdomains; preload") ("X-GitHub-Request-Id" . "510267F3:19B11:69AF2F7:55FB63E5") ("Access-Control-Allow-Origin" . "*") ("Access-Control-Expose-Headers" . "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval") ("Access-Control-Allow-Credentials" . "true") ("Content-Security-Policy" . "default-src 'none'") ("X-Frame-Options" . "deny") ("X-XSS-Protection" . "1; mode=block") ("X-RateLimit-Reset" . "1442539294") ("X-RateLimit-Remaining" . "57") ("X-RateLimit-Limit" . "60") ("X-GitHub-Media-Type" . "github.v3") ("Status" . "401 Unauthorized") ("Content-Length" . "83") ("Content-Type" . "application/json; charset=utf-8") ("Date" . "Fri, 18 Sep 2015 01:07:49 GMT") ("Server" . "GitHub.com") (status-string . "Unauthorized") (status-code . "401") (status-version . "1.1")) 401 nil (closure (t) (&rest args) (apply (quote gh-object-list-read) (quote gh-pulls-request) args)) [object gh-api-paged-request "gh-api-paged-request" "GET" "https://api.github.com/repos/sigma/gh.el/pulls" nil (("Authorization" . "token <CENSORED>") ("Content-Type" . "application/json")) "null" nil 0 nil]])
  apply(#[(req &optional resp) "\306\307\310�\311\"\310�\312\"\310�\313\"\310�\314\"\310�\315\"\211�\203!�\316  !\202\"�\317)P��������\310�\320\"\203\\���\206>�\321\310�\322\"!�����D��r\323\n\324��C#q\210\325\326!\210����+\202|���\206g�\321\310�\322\"!�����D��r\327\n!q\210\324\330��\"\210+.�\331\332\310�\333\"\"\210��\207" [req params url url-request-extra-headers url-request-data url-request-method (("basic" ignore . 4)) high eieio-oref :method :data :headers :url :query gh-url-params-encode "" :async make-instance default-response-cls url-retrieve gh-url-set-response make-local-variable url-registered-auth-schemes url-retrieve-synchronously nil mapc #[(cb) "\302�   \"\207" [resp cb gh-url-add-response-callback] 3] :install-callbacks url-privacy-level resp req-resp] 10] ([object gh-api-paged-request "gh-api-paged-request" "GET" "https://api.github.com/repos/sigma/gh.el/pulls" nil (("Authorization" . "token <CENSORED>") ("Content-Type" . "application/json")) "null" nil 0 nil] [object gh-api-paged-response "gh-api-paged-response" nil nil (("X-Content-Type-Options" . "nosniff") ("Strict-Transport-Security" . "max-age=31536000; includeSubdomains; preload") ("X-GitHub-Request-Id" . "510267F3:19B11:69AF2F7:55FB63E5") ("Access-Control-Allow-Origin" . "*") ("Access-Control-Expose-Headers" . "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval") ("Access-Control-Allow-Credentials" . "true") ("Content-Security-Policy" . "default-src 'none'") ("X-Frame-Options" . "deny") ("X-XSS-Protection" . "1; mode=block") ("X-RateLimit-Reset" . "1442539294") ("X-RateLimit-Remaining" . "57") ("X-RateLimit-Limit" . "60") ("X-GitHub-Media-Type" . "github.v3") ("Status" . "401 Unauthorized") ("Content-Length" . "83") ("Content-Type" . "application/json; charset=utf-8") ("Date" . "Fri, 18 Sep 2015 01:07:49 GMT") ("Server" . "GitHub.com") (status-string . "Unauthorized") (status-code . "401") (status-version . "1.1")) 401 nil (closure (t) (&rest args) (apply (quote gh-object-list-read) (quote gh-pulls-request) args)) [object gh-api-paged-request "gh-api-paged-request" "GET" "https://api.github.com/repos/sigma/gh.el/pulls" nil (("Authorization" . "token <CENSORED>") ("Content-Type" . "application/json")) "null" nil 0 nil]]))
  gh-url-run-request([object gh-api-paged-request "gh-api-paged-request" "GET" "https://api.github.com/repos/sigma/gh.el/pulls" nil (("Authorization" . "token <CENSORED>") ("Content-Type" . "application/json")) "null" nil 0 nil] [object gh-api-paged-response "gh-api-paged-response" nil nil (("X-Content-Type-Options" . "nosniff") ("Strict-Transport-Security" . "max-age=31536000; includeSubdomains; preload") ("X-GitHub-Request-Id" . "510267F3:19B11:69AF2F7:55FB63E5") ("Access-Control-Allow-Origin" . "*") ("Access-Control-Expose-Headers" . "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval") ("Access-Control-Allow-Credentials" . "true") ("Content-Security-Policy" . "default-src 'none'") ("X-Frame-Options" . "deny") ("X-XSS-Protection" . "1; mode=block") ("X-RateLimit-Reset" . "1442539294") ("X-RateLimit-Remaining" . "57") ("X-RateLimit-Limit" . "60") ("X-GitHub-Media-Type" . "github.v3") ("Status" . "401 Unauthorized") ("Content-Length" . "83") ("Content-Type" . "application/json; charset=utf-8") ("Date" . "Fri, 18 Sep 2015 01:07:49 GMT") ("Server" . "GitHub.com") (status-string . "Unauthorized") (status-code . "401") (status-version . "1.1")) 401 nil (closure (t) (&rest args) (apply (quote gh-object-list-read) (quote gh-pulls-request) args)) [object gh-api-paged-request "gh-api-paged-request" "GET" "https://api.github.com/repos/sigma/gh.el/pulls" nil (("Authorization" . "token <CENSORED>") ("Content-Type" . "application/json")) "null" nil 0 nil]])
  #[(api transformer method resource &optional data params) "\306�\307\"\211�\310=\203��\311\202��  \312=\205��\313�\306�\314\"�\f
\315\316\317�0\"!E�1�\2057�
\306�\320\"\235\2057��1\211�2\205B�\321��2\"\211�3\205M�\322��2\"�4�3\205Y�\323��2\"\211�5\205d�\324��2\"�6�3\203p��5\205\265�\325\306�\326\"\327\330\331
\332\306�\333\"\334�\f\"P\335�7\336�6\203\225�\337�6B\nB\202\226�\n\340 \312=\203\244�\341�8!\206\262�  \310=\203\261�\342�8!\206\262�\343&�\"�9�3\203\314��5\204\314�\344\345\346\347\340�4%\202$��2\203\373�\327\306�9\350\"\351�0#�:\352�9�:\"\210\353�:\327\354\314�\355�2\356�6&�\"\210�:)\202$��\203��\357��1\"\210\352�9\327\306�9\350\"\351�0#\"\202$�\352�9\327\306�9\350\"\351�0#\".\n\207" [api fmt headers cache resource method eieio-oref :data-format :form (("Content-Type" . "application/x-www-form-urlencoded")) :json (("Content-Type" . "application/json")) :cache sha1 format "%s" safe-methods pcache-has pcache-get gh-cache-outdated-p gh-cache-etag gh-auth-modify-request :auth make-instance gh-api-paged-request :method :url :base gh-api-expand-resource :query :headers "If-None-Match" :data gh-api-json-encode gh-url-form-encode "" gh-api-response "cached" :data-received t default-response-cls :transform gh-url-run-request gh-url-add-response-callback gh-api-callback :key :revive pcache-invalidate transformer key ...] 16]([object gh-pulls-api "api" t [object gh-cache "cache" "~/.emacs.d/var/pcache/cache" nil #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ( ...)) pcache-entry 1442520306.0517635 300] "https://api.github.com" "github" [object gh-oauth-authenticator "auth" "aspiers" "<CENSORED>"] :json 1 nil] (closure (t) (&rest args) (apply (quote gh-object-list-read) (quote gh-pulls-request) args)) "GET" "/repos/sigma/gh.el/pulls")
  apply(#[(api transformer method resource &optional data params) "\306�\307\"\211�\310=\203��\311\202��    \312=\205��\313�\306�\314\"�\f
\315\316\317�0\"!E�1�\2057�
\306�\320\"\235\2057��1\211�2\205B�\321��2\"\211�3\205M�\322��2\"�4�3\205Y�\323��2\"\211�5\205d�\324��2\"�6�3\203p��5\205\265�\325\306�\326\"\327\330\331
\332\306�\333\"\334�\f\"P\335�7\336�6\203\225�\337�6B\nB\202\226�\n\340 \312=\203\244�\341�8!\206\262�  \310=\203\261�\342�8!\206\262�\343&�\"�9�3\203\314��5\204\314�\344\345\346\347\340�4%\202$��2\203\373�\327\306�9\350\"\351�0#�:\352�9�:\"\210\353�:\327\354\314�\355�2\356�6&�\"\210�:)\202$��\203��\357��1\"\210\352�9\327\306�9\350\"\351�0#\"\202$�\352�9\327\306�9\350\"\351�0#\".\n\207" [api fmt headers cache resource method eieio-oref :data-format :form (("Content-Type" . "application/x-www-form-urlencoded")) :json (("Content-Type" . "application/json")) :cache sha1 format "%s" safe-methods pcache-has pcache-get gh-cache-outdated-p gh-cache-etag gh-auth-modify-request :auth make-instance gh-api-paged-request :method :url :base gh-api-expand-resource :query :headers "If-None-Match" :data gh-api-json-encode gh-url-form-encode "" gh-api-response "cached" :data-received t default-response-cls :transform gh-url-run-request gh-url-add-response-callback gh-api-callback :key :revive pcache-invalidate transformer key ...] 16] ([object gh-pulls-api "api" t [object gh-cache "cache" "~/.emacs.d/var/pcache/cache" nil #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ( ...)) pcache-entry 1442520306.0517635 300] "https://api.github.com" "github" [object gh-oauth-authenticator "auth" "aspiers" "<CENSORED>"] :json 1 nil] (closure (t) (&rest args) (apply (quote gh-object-list-read) (quote gh-pulls-request) args)) "GET" "/repos/sigma/gh.el/pulls"))
  gh-api-authenticated-request([object gh-pulls-api "api" t [object gh-cache "cache" "~/.emacs.d/var/pcache/cache" nil #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ( ...)) pcache-entry 1442520306.0517635 300] "https://api.github.com" "github" [object gh-oauth-authenticator "auth" "aspiers" "<CENSORED>"] :json 1 nil] (closure (t) (&rest args) (apply (quote gh-object-list-read) (quote gh-pulls-request) args)) "GET" "/repos/sigma/gh.el/pulls")
  #[(api user repo) "\303�\304\305�\306\"!\307\310\311  \n#$\207" [api user repo gh-api-authenticated-request gh-object-list-reader eieio-oref req-cls "GET" format "/repos/%s/%s/pulls"] 8]([object gh-pulls-api "api" t [object gh-cache "cache" "~/.emacs.d/var/pcache/cache" nil #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ( ...)) pcache-entry 1442520306.0517635 300] "https://api.github.com" "github" [object gh-oauth-authenticator "auth" "aspiers" "<CENSORED>"] :json 1 nil] "sigma" "gh.el")
  apply(#[(api user repo) "\303�\304\305�\306\"!\307\310\311    \n#$\207" [api user repo gh-api-authenticated-request gh-object-list-reader eieio-oref req-cls "GET" format "/repos/%s/%s/pulls"] 8] ([object gh-pulls-api "api" t [object gh-cache "cache" "~/.emacs.d/var/pcache/cache" nil #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ( ...)) pcache-entry 1442520306.0517635 300] "https://api.github.com" "github" [object gh-oauth-authenticator "auth" "aspiers" "<CENSORED>"] :json 1 nil] "sigma" "gh.el"))
  gh-pulls-list([object gh-pulls-api "api" t [object gh-cache "cache" "~/.emacs.d/var/pcache/cache" nil #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ( ...)) pcache-entry 1442520306.0517635 300] "https://api.github.com" "github" [object gh-oauth-authenticator "auth" "aspiers" "<CENSORED>"] :json 1 nil] "sigma" "gh.el")
  (if (not (and creds (car creds) (cdr creds))) (message "Remote repository is not configured or incorrect.") (magit-gh-pulls-purge-cache) (gh-pulls-list (magit-gh-pulls-get-api) (car creds) (cdr creds)) (magit-refresh))
  (let ((creds (magit-gh-pulls-guess-repo))) (if (not (and creds (car creds) (cdr creds))) (message "Remote repository is not configured or incorrect.") (magit-gh-pulls-purge-cache) (gh-pulls-list (magit-gh-pulls-get-api) (car creds) (cdr creds)) (magit-refresh)))
  magit-gh-pulls-reload()
  #<subr call-interactively>(magit-gh-pulls-reload record nil)
  ad-Advice-call-interactively(#<subr call-interactively> magit-gh-pulls-reload record nil)
  apply(ad-Advice-call-interactively #<subr call-interactively> (magit-gh-pulls-reload record nil))
  call-interactively(magit-gh-pulls-reload record nil)
  command-execute(magit-gh-pulls-reload record)
@sigma sigma modified the milestone: v1.0 Jun 26, 2016
@sigma sigma self-assigned this Jul 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants