Re: Exit status not reflecting 404 with --fail

Hans Henrik Bergan via curl-users <[email protected]>
Newsgroups gmane.comp.web.curl.general
Message-ID <CAJmy8YHb1z8a_68FureExZnh0VKqHHVX5YfizJo1OFC0Zm-dqQ@mail.gmail.com>
rule of thumb, use `type curl`  not `which curl`
(most often either works, but in some situations, `which curl` could
output /usr/bin/curl and `type curl` could output `curl is a shell
builtin` or whatever)

On Mon, 27 Nov 2023 at 11:04, Timothe Litt via curl-users
<[email protected]> wrote:
>
>
> On 26-Nov-23 23:42, Ray Satiro via curl-users wrote:
>
> 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?
>
> Sometimes curl isn't curl.
>
> I found the issue.  The user had aliased curl to a wrapper script that didn't properly pass on the exit code.
>
> curl --version doesn't show this.  Add to the checklist: 'which curl'.  Sigh.
>
> Sorry for the false alarm.  Thanks for looking at this.
>
> Timothe Litt
> ACM Distinguished Engineer
> --------------------------
> This communication may not represent the ACM or my employer's views,
> if any, on the matters discussed.
>
> --
> Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-users
> Etiquette:   https://curl.se/mail/etiquette.html
-- 
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-users
Etiquette:   https://curl.se/mail/etiquette.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.