tkf / emacs-request

Request.el -- Easy HTTP request for Emacs Lisp
http://tkf.github.com/emacs-request/
GNU General Public License v3.0
629 stars 93 forks source link

Confusing error logs in *Messages* #206

Closed junjizhi closed 2 years ago

junjizhi commented 2 years ago

Environment

Example I tried

(require 'request)
(setq request-backend 'url-retrieve)
(request "http://httpbin.org/post"
  :type "POST"
  :data '(("key" . "value") ("key2" . "value2"))
  ;; :data "key=value&key2=value2"  ;; this is equivalent
  :parser 'json-read
  :success (cl-function
            (lambda (&key data &allow-other-keys)
              (message "I sent something"))))

error in Messages buffer:

#s(request-response nil nil nil nil nil "http://httpbin.org/post" nil (:type "POST" :data "key=value&key2=value2" :parser json-read :success (closure (t) (&rest --cl-rest--) "

(fn &key DATA &allow-other-keys)" (let* ((data (car (cdr (plist-member --cl-rest-- ':data))))) (message "I sent something"))) :error #[128 "ÆÇ\"A@ȉÉ!    !
!]X…HÊËÉÊÌÀ¢
##Xƒ<rÍ!qˆÎ‰dbˆ‰Ï±ˆ*X…FÐÑ\"²¶ƒ²‡" [("http://httpbin.org/post") request-log-level request-message-level request-log-buffer-name buffer-read-only inhibit-read-only plist-member :symbol-status #[257 "‰¨ƒ‡‰žA†Á‡" [request--log-level-def 0] 3 "

(fn LEVEL)"] error format "[%s] %s" "request-default-error-callback: %s %s" get-buffer-create t "
" message "%s"] 14 "

(fn &rest ARGS &key SYMBOL-STATUS &allow-other-keys)"] :url "http://httpbin.org/post" :response #0 :encoding utf-8) #<buffer  *http httpbin.org:80*> nil nil url-retrieve)
I sent something

Temporary work-around

I tried the suggested approach to assign it a result and it worked fine for now:

(let (result)
  (request
    "http://httpbin.org/post"
    :type "POST"
    :data '(("key" . "value") ("key2" . "value2"))
    :sync t
    :parser 'json-read
    :success (cl-function
              (lambda (&key data &allow-other-keys)
                (setq result (format "I sent: %S" (assoc-default 'form data))))))
  result)

Questions

[request--log-level-def 0] 3 "

(fn LEVEL)"] error format "[%s] %s" "request-default-error-callback: %s %s" get-buffer-create t "
" message "%s"] 14

Is this an actual error?

dickmao commented 2 years ago

Yes, it's very offputting that it returns a composite object whose string manifestation includes its error handler.