Error handling in the constructor of a VMOD object
Carlos Abalde
carlos.abalde at gmail.com
Tue Sep 17 09:54:01 UTC 2024
Hi all,
I'm looking for advise / best-practices related to VMODs, objects and
their __init() constructors. Let's assume a foo VMOD and a VCL like this
one:
import foo;
sub vcl_init {
new myfoo = foo.instance(...);
...
}
What's your suggestion to handle errors in the constructor? So far my
approach is returning a NULL pointer if for some reason the instance
cannot be created, which IMO is good enough because that way execution
of 'vcl_init' will continue (meh...), but in the end it will fail (with
a slightly obscure error), and then the VCL won't be loaded. However, in
such a scenario ans using that strategy, a VCL like this one would
trigger a panic:
sub vcl_init {
new myfoo = foo.instance(...);
myfoo.whatever(...);
...
}
Transforming all VMOD methods in no-ops when the received pointer is
NULL could be an option, but it looks ugly. I guess another option would
be to add a '.isnull()' method to the object and then use it in 'vcl_init':
sub vcl_init {
new myfoo = foo.instance(...);
if (myfoo.isnull()) {
return (fail);
}
myfoo.whatever(...);
...
}
My doubt is if I'm missing something and a better approach already
exists for error handling during 'vcl_init'. Any suggestion?
Thanks,
--
Carlos Abalde
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-dev/attachments/20240917/631f5dfa/attachment.html>
More information about the varnish-dev
mailing list