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: Exit status not reflecting 404 with --fail

From: Ray Satiro via curl-users <curl-users_at_lists.haxx.se>
Date: Sun, 26 Nov 2023 23:42:32 -0500

On 11/26/2023 9:51 PM, Timothe Litt via curl-users wrote:
>
> This reproducer appears to show a bug that prevents scripts from using
> the exit code to detect a 4xx failure:
>
> # curl  -w "%{stderr}x:%{exitcode} r:%{response_code}\n" --fail
> https://www.google.com/nosuchuri >/dev/null
>   % Total    % Received % Xferd  Average Speed   Time Time     Time 
> Current
>                                  Dload  Upload   Total Spent    Left 
> Speed
>   0  1570    0     0    0     0      0      0 --:--:-- --:--:--
> --:--:--     0
> curl: (22) The requested URL returned error: 404
> x:22 r:404
>
> # echo $?
> 0
>
> The error message is correct, but since --fail is specified I expected
> $? to be 22.  Note from the -w that the exitcode is set to 22, but is
> not delivered to the shell.
>
> The response code is 404.
>
> Same behavior if the (diagnostic) -w is omitted... (and/or -s added)
>

I can't reproduce this in Linux or in Windows. Can you show the verbose
output? What options are in your curlrc?

-- 
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-users
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2023-11-27