Error handling in the constructor of a VMOD object

Geoff Simmons geoff at uplex.de
Tue Sep 17 10:55:52 UTC 2024


On 9/17/24 11:54, Carlos Abalde wrote:
> 
> I'm looking for advise / best-practices related to VMODs, objects and 
> their __init() constructors.
> What's your suggestion to handle errors in the constructor?
if (failure) {
	VRT_fail(ctx, "printf-like format %string", args, ...);
	return;
}

When VRT_fail() is invoked during the function implementing the 
constructor, the execution of vcl_init is aborted, and the VCL load fails.

The CLI prints an error message that the VCL "Failed initialization", 
and then the formatted message from VRT_fail() in the next line. That's 
where you can describe the error.

It's very much like a VCL compile failure in that the VCL doesn't load. 
The difference being that the CLI returns status 300 for an 
initialization failure, but 106 for a syntax error.

You might want the return right after VRT_fail(), unless you have to do 
some resource cleanup first. At any rate, you can discontinue the C 
function as soon as possible.


HTH,
Geoff
-- 
** * * UPLEX - Nils Goroll Systemoptimierung

Scheffelstraße 32
22301 Hamburg

Tel +49 40 2880 5731
Mob +49 176 636 90917
Fax +49 40 42949753

http://uplex.de

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-dev/attachments/20240917/b7400b2a/attachment.bin>


More information about the varnish-dev mailing list