curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: Printing the URL in the error messages when --fail is passed?

From: Timothe Litt <litt_at_acm.org>
Date: Sun, 24 Jul 2022 12:07:44 -0400

I still think that the default is unhelpful and should be changed.

While it is possible to work around  this with a custom -w, it shouldn't
be necessary.

A basic rule of UI design is that error messages should tell the
consumer what is wrong.  This is a case where curl doesn't, and should
do better...

-w is very helpful when one wants to get non-default details or format
information for a script.

This is not such a case.  This is a common case on a command line (not
just in scripts), and the error message is not specifying the object of
the failing operation.  As Bhavin has pointed out, the object (URL) is
essential for understanding what happened.  It should not be necessary
to learn and enter a complex formatting string to get it.

Requiring -w for urlnum seems fine - that's the sort of thing that a
script might use, but a human is unlikely to.  Likewise, if a script
wanted each url and status on a separate line, or wrapped in quotes, or
setup for a bash associative array - -w is the right tool.

But the current behavior is analogous to

cp z* x* foo/

returning 'file not found' instead of "cp: cannot stat 'x*': No such
file or directory".

cp does the right thing...  curl should too.

Timothe Litt
ACM Distinguished Engineer
--------------------------
This communication may not represent the ACM or my employer's views,
if any, on the matters discussed.

On 24-Jul-22 10:59, Bhavin Gandhi wrote:
> On Sun, 24 Jul 2022 at 19:28, Daniel Stenberg <daniel_at_haxx.se> wrote:
>>> Is there any other command line option which can help here? I was not
>>> able to find anything relevant in the manual as well as on the Internet
>>> after a few searches.
>> -w is your friend.
>>
>> I blogged about it to some length a while ago:
>>
>> https://daniel.haxx.se/blog/2021/01/27/curl-your-own-error-message/
>>
> Aha! I was aware of -w, but this didn't occur to me that I can use it
> for error as well. I should have read the manual carefully, especially
> the -w section.
> This solves the above issue, and I don't think the default behavior
> needs to
> be changed. Thank you!
>
> I came up with the following one for my use case:
>
> $ curl --write-out '%{onerror}%{urlnum}: %{url}: %{errormsg}\n' \
> --parallel --fail --silent \
> https://curl.se/nothing-404 https://curl.se/nothing-404-2
>
> 1: https://curl.se/nothing-404-2: The requested URL returned error: 404
> 0: https://curl.se/nothing-404: The requested URL returned error: 404
>
> Thank you Timothe for sharing your thoughts about it :)
>

-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-users
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2022-07-24