<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hi all,<br>
<br>
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:<br>
<br>
<font face="monospace">import foo;<br>
<br>
sub vcl_init {<br>
new myfoo = foo.instance(...);<br>
<br>
...<br>
}</font><br>
<br>
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:<br>
<br>
<font face="monospace">sub vcl_init {<br>
new myfoo = foo.instance(...);<br>
myfoo.whatever(...);<br>
<br>
...<br>
}</font><br>
<br>
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':<br>
<br>
<font face="monospace">sub vcl_init {<br>
new myfoo = foo.instance(...);<br>
if (myfoo.isnull()) {<br>
return (fail);<br>
}<br>
<br>
myfoo.whatever(...);<br>
<br>
...<br>
}</font><br>
<br>
My doubt is if I'm missing something and a better approach already
exists for error handling during 'vcl_init'. Any suggestion?<br>
</p>
<p>Thanks,<br>
</p>
<div class="moz-signature">-- <br>
Carlos Abalde</div>
</body>
</html>