Re: Add -fail_on_alert option to exit with error on alerts

Thomas Dickey <[email protected]> Thu, 7 May 2026 19:38:08 -0400
Newsgroups gmane.comp.web.lynx.devel
Message-ID <[email protected]>
--lzA8U6pSqF3DU7xa
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, May 07, 2026 at 07:22:13PM +0000, WaitronCharm via Lynx-dev wrote:
> Hello,
>=20
> I would like to propose the following patch for Lynx 2.9.0:

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

hmm - most but not all calls to HTAlert are urgent.  I see some cases
where you might not want to exit immediately:

src/GridText.c:13908:		HTAlert(gettext("Very long lines have been truncated=
!"));
src/HTFWriter.c:990:	    HTAlert(EXECUTION_DISABLED);
src/LYLocal.c:354:	HTAlert(gettext("The selected item is not a file or a di=
rectory!  Request ignored."));
src/LYLocal.c:676:	HTAlert(gettext("There is already a directory with that =
name!  Request ignored."));
src/LYLocal.c:678:	HTAlert(gettext("There is already a file with that name!=
  Request ignored."));
src/LYMain.c:2438:	    HTAlert(gettext("persistent cookies state will be ch=
anged in next session only."));
src/LYMainLoop.c:5399:	HTAlert(SHIFT_VS_LINEWRAP);
src/LYOptions.c:3399:		    HTAlert(UA_PLEASE_USE_LYNX);

>=20
> $ diff lynx2.9.0/src/LYGlobalDefs.h.orig lynx2.9.0/src/LYGlobalDefs.h
> 669a670,671
> >     extern BOOLEAN LYFailOnAlert;
> >     extern BOOLEAN alert_occurred;
>=20
> $ 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",	4|SET_ARG,		LYFailOnAlert,
> >       "exit with error code if any alert is written"
> >    ),
>=20
>=20
> This patch introduces a new command-line option, -fail_on_alert, and a co=
rresponding global flag LYFailOnAlert.
>=20
> The patch modifies HTAlert.c, LYGlobalDefs.h, and LYMain.c to track wheth=
er an alert has occurred during a session. If the -fail_on_alert flag is se=
t and the alert_occurred boolean is triggered, Lynx will now exit with EXIT=
_FAILURE regardless of the standard exit code.
>=20
> Currently, detecting if a Lynx session encountered an alert (such as a 40=
3 Forbidden error) from a script is unnecessarily difficult. Without this p=
atch, one has to resort to convoluted shell piping and stderr scraping, for=
 example:
>=20
> 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>&-) > ...
>=20
> This approach is brittle and hard to maintain. Providing a built-in way t=
o fail on alerts aligns Lynx with similar functional options available in o=
ther CLI tools like curl (--fail) and wget.
>=20
> I believe this is a useful addition for anyone using Lynx in automated en=
vironments or CI/CD pipelines.
>=20
>=20

--=20
Thomas E. Dickey <[email protected]>
https://invisible-island.net

--lzA8U6pSqF3DU7xa
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQGzBAABCgAdFiEEGYgtkt2kxADCLA1WzCr0RyFnvgMFAmn9IlsACgkQzCr0RyFn
vgNsfAv/QgaxLn69VpZC+HlTuPveovqqzh5Nv3tVOGYq2R1juepCcFakHjpXglzC
QydJLNHFLgKoF+AFd582fzqsCiGsmArZUoxZxl8xvmmrrY2BhVzN+5CO0b/iizeH
sSLGUXA076lm881rDW2VUeodG2BV8Ec37G1xjzcfTqoQQxdr9wMNn/R5vw6/9vGj
lnlFIwy9fsN4rSo0zLfR+DxFNwdj7RLShmmxb0RaZ5/KJYKASE/UNYBlkkAev2N+
XGHxIsyuXW0WAyqy+oBv+o+aaUl+EkDyYeZeicYTsZUCUCpo2Z6HbJIxAXYkFQ8H
bspFEiTrYWAFIyjbqhvJLAsdk7RvXls1R2Hfzb5VkR2AgJxPLpbCVK5ehTKVnAQU
VP4VCPEe5i7aFXr68ZzNOXH0zONaeu86rhyvXiKIBmhXu87/JbpBeCl6un7uizJy
IlIxKzuPOmxpHN0ARqB8adLT+GnFKXllsgsjuqrsCU5RXrmFfRH7uw9ei25g7d/O
SkEATfOe
=MOjO
-----END PGP SIGNATURE-----

--lzA8U6pSqF3DU7xa--