alphapapa / plz.el

An HTTP library for Emacs
GNU General Public License v3.0
200 stars 11 forks source link

Impossible to handle error when calling synchronously #21

Closed Fuco1 closed 1 year ago

Fuco1 commented 1 year ago

It seems that when called synchronously, a signal is thrown but then an unwind-protect catches it and it is never exposed to the called. I would like to be able to just get the error as return value in case of an error when called synchronously.

alphapapa commented 1 year ago

Hi Matus,

I'm not sure what you mean. AFAICT, unwind-protect doesn't have that effect. For example, when I eval this form:

(condition-case err
    (unwind-protect
        (progn
          (message "before error")
          (signal 'error "error")
          (message "after error"))
      (message "unwind"))
  (error (message "handler")))

I see these messages:

before error
unwind
handler

So both the UNWINDFORM and the HANDLER are evaluated.

Also, evaluating this form signals an error, as expected:

(plz 'get "https://notarealdomainfoobar.com")
Debugger entered--Lisp error: (plz-curl-error . #s(plz-error :curl-error (6 . "Couldn't resolve host. The given remote host was n...") :response nil :message nil))
  plz--sentinel(#<process plz-request-curl<1>> "exited abnormally with code 6\n")
  plz(get "https://notarealdomainfoobar.com")
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  command-execute(eval-last-sexp)

If you want to ignore the error signal and just get nil as the return value if a synchronous request fails, you can use :else #'ignore, like:

(plz 'get "https://notarealdomainfoobar.com" :else #'ignore)

Or you could wrap it in ignore-errors, of course.

Is that what you mean?

Fuco1 commented 1 year ago

~If I evaluate the plz form all I get is the following in the messages buffer~

error in process sentinel: let: Curl error
error in process sentinel: Curl error

~I'm on emacs 28.2 if that's worth anything. But I'm going to assume I'm doing something wrong because what you say sounds logical. The condition-case example returns the same as what you described.~

I just reloaded the package and it works :man_facepalming: Sorry for the noise.

alphapapa commented 1 year ago

No problem, thanks. Please let me know if you have any other feedback on the library.