Add -fail_on_alert option to exit with error on alerts

WaitronCharm via Lynx-dev <[email protected]> Thu, 07 May 2026 19:22:13 +0000
Newsgroups gmane.comp.web.lynx.devel
Message-ID <9bB0KdXuWUev-ZqRmtR1WWnIL8IsrAk1cha6yaWM2n4ADAAk1-1vtrBLSqQqFo_xVoG5SOtn28i_5kJ_ipYGTcF6gTk6RIIMtEDBnskyTjw=@proton.me>
Hello,

I would like to propose the following patch for Lynx 2.9.0:


$ diff lynx2.9.0/src/HTAlert.c.orig lynx2.9.0/src/HTAlert.c
62a63,66
>     if (LYFailOnAlert) {
>         alert_occurred =3D TRUE;
>     }
>=20

$ diff lynx2.9.0/src/LYGlobalDefs.h.orig lynx2.9.0/src/LYGlobalDefs.h
669a670,671
>     extern BOOLEAN LYFailOnAlert;
>     extern BOOLEAN alert_occurred;

$ diff lynx2.9.0/src/LYMain.c.orig lynx2.9.0/src/LYMain.c
731a732,734
> BOOLEAN LYFailOnAlert =3D FALSE;
> BOOLEAN alert_occurred =3D FALSE;
>=20
919c922,927
<     exit(code);
---
>=20
>     if (LYFailOnAlert && alert_occurred) {
>         exit(EXIT_FAILURE);
>     } else {
>         exit(code);
>     }
3548a3557,3560
>    PARSE_SET(
>       "fail_on_alert",=094|SET_ARG,=09=09LYFailOnAlert,
>       "exit with error code if any alert is written"
>    ),


This patch introduces a new command-line option, -fail_on_alert, and a corr=
esponding global flag LYFailOnAlert.

The patch modifies HTAlert.c, LYGlobalDefs.h, and LYMain.c to track whether=
 an alert has occurred during a session. If the -fail_on_alert flag is set =
and the alert_occurred boolean is triggered, Lynx will now exit with EXIT_F=
AILURE regardless of the standard exit code.

Currently, detecting if a Lynx session encountered an alert (such as a 403 =
Forbidden error) from a script is unnecessarily difficult. Without this pat=
ch, one has to resort to convoluted shell piping and stderr scraping, for e=
xample:

set -e; set -o pipefail; ((lynx -stderr -source "$URL" 3>&1 1>&2 2>&3 3>&- =
| (grep -F -x 'Alert!: HTTP/1.0 403 Forbidden' || test $? -eq 1) | cmp -s -=
 /dev/null) 3>&1 1>&2 2>&3 3>&-) > ...

This approach is brittle and hard to maintain. Providing a built-in way to =
fail on alerts aligns Lynx with similar functional options available in oth=
er CLI tools like curl (--fail) and wget.

I believe this is a useful addition for anyone using Lynx in automated envi=
ronments or CI/CD pipelines.