[SCM] libmessage-passing-perl Debian packaging branch, master, updated. debian/0.111-3-14-g44f6e88
Tomas Doran
bobtfish at bobtfish.net
Mon May 6 11:57:39 UTC 2013
The following commit has been merged in the master branch:
commit a0bcb41427d6a5b308d8df7755f80a1598e0a4db
Author: Tomas Doran <bobtfish at bobtfish.net>
Date: Sun Aug 26 10:03:22 2012 +0100
Make error chains more useful
diff --git a/Changes b/Changes
index 26f999f..89b6e5a 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,9 @@
+ - Add error chain support to the JSON encoder so that an error is
+ logged if JSON encoding fails.
+
+ - Make default error chain do JSON encoding on errors so that they're
+ readable.
+
0.101
- Fix daemonization features provided by Message::Passing::Role::Script
to work on the command line again by exlicitly using MooX::Options
diff --git a/lib/Message/Passing/Filter/Encoder/JSON.pm b/lib/Message/Passing/Filter/Encoder/JSON.pm
index 956b980..3980775 100644
--- a/lib/Message/Passing/Filter/Encoder/JSON.pm
+++ b/lib/Message/Passing/Filter/Encoder/JSON.pm
@@ -3,9 +3,14 @@ use Moo;
use MooX::Types::MooseLike::Base qw/ Bool /;
use JSON qw/ to_json /;
use Scalar::Util qw/ blessed /;
+use Try::Tiny;
+use Data::Dumper ();
use namespace::clean -except => 'meta';
-with 'Message::Passing::Role::Filter';
+with qw/
+ Message::Passing::Role::Filter
+ Message::Passing::Role::HasErrorChain
+/;
has pretty => (
isa => Bool,
@@ -15,19 +20,28 @@ has pretty => (
sub filter {
my ($self, $message) = @_;
- return $message unless ref($message);
- if (blessed $message) { # FIXME - This should be moved out of here!
- if ($message->can('pack')) {
- $message = $message->pack;
- }
- elsif ($message->can('to_hash')) {
- $message = $message->to_hash;
+ try {
+ return $message unless ref($message);
+ if (blessed $message) { # FIXME - This should be moved out of here!
+ if ($message->can('pack')) {
+ $message = $message->pack;
+ }
+ elsif ($message->can('to_hash')) {
+ $message = $message->to_hash;
+ }
}
+ to_json( $message, { utf8 => 1, $self->pretty ? (pretty => 1) : () } )
+ }
+ catch {
+ $self->error->consume({
+ class => 'Message::Passing::Exception::Encoding',
+ exception => $_,
+ stringified_data => Data::Dumper::Dumper($message),
+ });
+ return; # Explicitly drop the message from normal processing
}
- to_json( $message, { utf8 => 1, $self->pretty ? (pretty => 1) : () } )
}
-
1;
=head1 NAME
@@ -82,4 +96,5 @@ the SureVoIP API -
See L<Message::Passing>.
-=cut
\ No newline at end of file
+=cut
+
diff --git a/lib/Message/Passing/Role/HasErrorChain.pm b/lib/Message/Passing/Role/HasErrorChain.pm
index 84907ef..3b807d6 100644
--- a/lib/Message/Passing/Role/HasErrorChain.pm
+++ b/lib/Message/Passing/Role/HasErrorChain.pm
@@ -1,13 +1,18 @@
package Message::Passing::Role::HasErrorChain;
use Moo::Role;
-use Message::Passing::Output::STDERR;
+use Module::Runtime qw/ require_module /;
use namespace::clean -except => 'meta';
has error => (
is => 'ro',
default => sub {
- Message::Passing::Output::STDERR->new;
+ require_module 'Message::Passing::Output::STDERR';
+ require_module 'Message::Passing::Filter::Encoder::JSON';
+ Message::Passing::Filter::Encoder::JSON->new(
+ output_to => Message::Passing::Output::STDERR->new,
+ );
},
+ lazy => 1,
);
1;
@@ -43,16 +48,44 @@ Some components can create an error stream in addition to a message stream.
An attribute containing the error chain.
+By default, this is a chain of:
+
+=over
+
+=item Message::Passing::Filter::Encoder::JSON
+
+=item Message::Passing::Output::STDOUT
+
+=back
+
+=head1 WARNINGS
+
+=head2 ERROR CHAINS CAN LOOP
+
+If you override the error chain output, be sure that the error chain does not go into your
+normal log path! This is because if you suddenly have errors in your normal log path, and you
+then start logging these errors, this causes more errors - causing you to generate a message loop.
+
+=head2 ENCODING IN ERROR CHAINS
+
+If you emit something which cannot be encoded to an error chain then the encoding
+error will likely be emitted by the error chain - this can again cause loops and other
+issues.
+
+All components which use error chains should be very careful to output data which
+they are entirely certain will be able to be encoded.
+
=head1 SPONSORSHIP
This module exists due to the wonderful people at Suretec Systems Ltd.
<http://www.suretecsystems.com/> who sponsored its development for its
VoIP division called SureVoIP <http://www.surevoip.co.uk/> for use with
-the SureVoIP API -
+the SureVoIP API -
<http://www.surevoip.co.uk/support/wiki/api_documentation>
=head1 AUTHOR, COPYRIGHT AND LICENSE
See L<Message::Passing>.
-=cut
\ No newline at end of file
+=cut
+
--
libmessage-passing-perl Debian packaging
More information about the Pkg-perl-cvs-commits
mailing list