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
_______________________________________________
varnish-dev mailing list
varnish-dev@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev

Reply via email to