Re: Exit status not reflecting 404 with --fail

Timothe Litt via curl-users <[email protected]>
Newsgroups gmane.comp.web.curl.general
Message-ID <[email protected]>
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
OpenPGP_signature.asc (application/pgp-signature, 495 B)
-----BEGIN PGP SIGNATURE-----

wsB5BAABCAAjFiEE0UvvF0GpbrNhifE5DTaRiR4XoSQFAmVkaY0FAwAAAAAACgkQDTaRiR4XoST+
Fgf9FbCtszGE133tNsX+VutUsqabUxTWM0enIpQ+4R+4D72SxKoVOYOMCcV/38oP2+25rpYofAgD
0UJGMqeRkQpHAYc6oFvAJoPjp8jhOUSs+GHNH73+l0eW14US4GPS3UVvcEuMS6Tg/XFtrEeh1fo4
qmpkpEh7oOhbtBkMu13waTIEhZlJm/2/tNiTNzAjKp2RoVSSYAtmEprNgIN0xM1DwRwXeJbsHIlr
715TkEFXrKNzaYYaqkfWZpHzbGMSizNZ369NM/xRFQBPxfF9J5eH0uPIzJgYp5b3w6a7jijfC15v
Wty9/8zKICU0uvnNL2BVCJ2kZ41Tmp6NrkrYUSd2yQ==
=Uq8W
-----END PGP SIGNATURE-----
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.