plenary.nvim icon indicating copy to clipboard operation
plenary.nvim copied to clipboard

Improve `curl` error handling

Open wyattjsmith1 opened this issue 3 years ago • 2 comments

In 40634fa, a change was introduced which caused any curl with a non-zero status code to call error with more information. I have found the forced error call to be problematic in my project. The tldr; is we are periodically calling curl to fetch data. This works fine, but when I close my laptop and come back an hour later, vim is littered with error messages due to curl attempts while there was no active network connection. I would prefer to handle these in a callback.

Normally a pcall is the best way to resolve this, but this isn't working; I suspect because it is an async call.

local result = pcall(function()
  curl.get { .... }
end)
if not result then
  -- Handle result
end

I think some better solutions are:

  1. Don't call error. I don't think this commit actually solves the problem cited because the response is still attempted to be parsed after error is called.
  2. Fire the callback method with/return some error structure.
  3. Have error be some toggled setting. e.g. curl.get { ..., display_error = false }

Please let me know what you think and if there is something I am misunderstanding about curl. Thanks for providing this library!

wyattjsmith1 avatar Jan 05 '22 19:01 wyattjsmith1

Don't call error. I don't think this commit actually solves the problem cited because the response is still attempted to be parsed after error is called.

Calling error is fine because it stops execution so it doesn't parse it but maybe a way to not error out but rather silently fail is fine. Also 2. would also be a fine solution. PR welcome

Conni2461 avatar Mar 20 '22 14:03 Conni2461

Is this still relevant?

Conni2461 avatar May 12 '22 15:05 Conni2461