Exit status not reflecting 404 with --fail
Timothe Litt via curl-users <[email protected]>
| Newsgroups | gmane.comp.web.curl.general |
|---|---|
| Message-ID | <[email protected]> |
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)
curl --version
curl 8.4.0 (i686-pc-linux-gnu) libcurl/8.4.0 OpenSSL/1.1.1d zlib/1.2.11
brotli/1.0.7 zstd/1.4.9 c-ares/1.15.0 libssh2/1.8.2 nghttp2/1.37.0
OpenLDAP/2.4.47
Release-Date: 2023-10-11
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap
ldaps mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli HSTS HTTP2 HTTPS-proxy IPv6 Largefile
libz NTLM NTLM_WB SSL threadsafe TLS-SRP UnixSockets zstd
--
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----- wsB5BAABCAAjFiEE0UvvF0GpbrNhifE5DTaRiR4XoSQFAmVkBCYFAwAAAAAACgkQDTaRiR4XoST4 5AgAndHTZsk7F0T9MiES4WHSZCIyiv/DE2DCEFAf4UTQqZ43FtcfRwDwPTEpjgWqJBA5Y/5BRf/x sixbwXKEtrkVBjCtFG7HwwHwXdqmxKnLlPmQqnBqNTlDV3jMNxxQi9qwJd+MANi78k8VQEnxRoBP aEuP/O5QZUg/RvoVkejKcVbDY2Y+s73lLJOkB/iKfVbHYvtv/O7V7pDEiFQ1FuZj9TIdADbnyNmU ApaF1ypmA2773Ekn3iwga1sDRUXWPpbVsPO2R8CIrhMttWzKu4FyokzIlsDugMPkA9wTH/ZYN+iz csgs0WQAjifQ2lO56Ya9EZZOdp107IK8y+aX2yR1lw== =90hT -----END PGP SIGNATURE-----