[PATCH] AnyEvent::Handle

Marc Lehmann schmorp at schmorp.de
Tue Jul 3 20:30:40 CEST 2012

On Tue, Jul 03, 2012 at 12:00:36PM +0200, Maxime Soulé <btik-cpan at scoubidou.com> wrote:
> Because this behavior is not consistent across all type readers. With

Actually, the behaviour is consistently undefined over all read types.

> I have in mind general application exceptions, like a perl critical
> one.

What is a perl critical exception?

> I prefer to handle this fatal case at the application level than
> to hide it behind an error code EBADMSG and continuing to work.

And nothing in AnyEvent prevents that from you. In fact, it even encourages
you to catch exceptions. It does not catch exceptions for you (unless you use
AE_DEBUG_WRAP or something similar).

Note that netither catching or letting through, an exception from a read
type, will cause  anything remotely similar to "handling at application
level", because you are always at a whim of whatever is in your callstack,
which most often is the event loop.

If you want any kind of specific behaviour, then you need to implement
that.  Relying on whoever else is up the stack is not going to work.

> >In fact, if caught via this mechanism it at least has a chance of getting
> >reported in a defined way (although it's still a bug).
> Or not

Since ou disagree, can you describe the mechanism that takes away the
chance of it being reported?

> When an EBADMSG is reported, it says that probably the client sent
> wrong data, so we can disconnect it and continue to work.

No, *any* program behaviour can always be caused by a bug as wlel, as
would be the case in this case.

> In the application fatal error case, it is not the same, the problem
> can be (and is probably) more serious...

AnyEvent cannot know which errors are and are not fatal to your
application. It could wrap each watcher callback into an eval to get some
defined behaviour (and you can do that using the wrap functionality), but
it does not enforce this.

Exceptions thrown from callbacks simply result in undefined behaviour, not
"application level error handling" or anything else. And I really mean
undefined behaviour - sometimes you get random memory corruption, sometimes
you get a message on stderr, sometimes it gets ignored, and sometimes you get
even more funny behaviour.

It is simply a bug, no matter what AnyEvent::Handle does.

                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
      -=====/_/_//_/\_,_/ /_/\_\

More information about the anyevent mailing list