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.

Exit status not reflecting 404 with --fail

From: Timothe Litt <litt_at_acm.org>
Date: Sun, 26 Nov 2023 21:51:18 -0500

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
Received on 2023-11-27