Subject: Developers of Sympa
List archive
- From: Guillaume Rousse <address@concealed>
- To: address@concealed
- Subject: Re: [sympa-developpers] Log functions
- Date: Mon, 19 Aug 2013 15:26:51 +0200
Le 07/08/2013 18:08, IKEDA Soji a écrit :
First, you're confusing catching and analysing exceptions here. Second, even string-based exceptions, such as raised by die() or croak() already allow minimal analysis. We really don't care if that's a "false" or "true" model, as long as it works sufficiently for our needs.- fatal_err() vs. croak().It just predates usage of exceptions, and should better be dropped in
fatal_err() seems to be replaced by croak() in most cases.
Former requires Sympa module, while latter needs just a standard
Carp module.
What are pros to use fatal_err()?
favor a exception handler in top-level code.
You proposed it before. I have carefully thought on it for
a while, and personally concluded that it would not be adopted.
Perl5 does not have true exception handling such as
"try-except-finally-else" structure and "raise" statement (e.g. in
Python). Behaviors of eval() and die() [or croak()] sometimes look
similar, however, they may be rather a Perl version of setjmp(3) and
longjmp(3).
To express exception handling by Perl5, code will be forced to be
slightly complex. Though some CPAN modules have been proposed to
ease it, they often fail to implement perfect syntax for exception
handling.
So my conclusion is: We should not try to emulate exception handling
on Perl5, although I deeply feel how better Perl5 had supported it.
fatal_error("foobar") logs "foobar", send a notification to listmaster, then call exit. It doesn't have any understanding of what exact the problem is, it just ensure proper recording of the event before exiting. You can achieve exactly the same result by wrapping the main infinite loop of all daemons:
eval {
while (1) {
# do some stuff here...
}
};
if ($EVAL_ERROR) {
log("something wrong happened: $EVAL_ERROR");
notify("something wrong happened: $EVAL_ERROR");
exit(1);
}
Code using fatal_error("foobar") hardcodes the logic "foobar message goes to syslog then to sendmail command, then everything stops". Code using croak("foobar") instead is much more flexible, as the error flow can be handled differently according to the context. When recovery is possible, for instance, there is no reason to quit. In unit testing scenario, you also need to re-route the error message without having to dig in actual syslog content. Etc...
Morevoer, you were the first one to implement such an exception handler in Sympa::Site, so I really don't understand this sudden change of mind...
--
Guillaume Rousse
INRIA, Direction des systèmes d'information
Domaine de Voluceau
Rocquencourt - BP 105
78153 Le Chesnay
Tel: 01 39 63 58 31
Attachment:
smime.p7s
Description: Signature cryptographique S/MIME
-
[sympa-developpers] Log functions,
IKEDA Soji, 08/05/2013
-
Re: [sympa-developpers] Log functions,
Guillaume Rousse, 08/05/2013
-
Re: [sympa-developpers] Log functions,
IKEDA Soji, 08/07/2013
- Re: [sympa-developpers] Log functions, IKEDA Soji, 08/08/2013
-
Re: [sympa-developpers] Log functions,
Guillaume Rousse, 08/19/2013
- Re: [sympa-developpers] Log functions, IKEDA Soji, 08/19/2013
-
Re: [sympa-developpers] Log functions,
IKEDA Soji, 08/07/2013
-
Re: [sympa-developpers] Log functions,
Guillaume Rousse, 08/05/2013
Archive powered by MHonArc 2.6.19+.