Messag...orChain(3pm)

πŸ“¦
version 0.117 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute

πŸ’– Messag...orChain(3pm) β€” bestie edition πŸ’–

okay so this is a page from the User Contributed Perl Documentation, and the header on it is literally Messag...orChain(3pm) because somebody's terminal was NOT about to fit the whole name in there. iconic behaviour honestly. anyway, sit down, grab a strawberry πŸ“, we're learning about error chains.


✨ NAME ✨

Message::Passing::Role::HasErrorChain β€” it's a role for components which can report errors. that's it, that's the whole vibe. a role that lets your component have opinions about things going wrong πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

so here's how you'd actually use it. note the little disclaimer at the top because we do NOT want you out here looking for a package that doesn't exist:

# Note this is an example package, and does not really exist!
package Message::Passing::Output::ErrorAllMessages;
use Moo;
use namespace::clean -except => 'meta';

with qw/
    Message::Passing::Role::Output
    Message::Passing::Role::HasErrorChain
/;

sub consume {
    my ($self, $message) = @_;
    $self->error->consume($message);
}

see how it with-es in both Message::Passing::Role::Output and Message::Passing::Role::HasErrorChain? then consume just shoves the message straight into $self->error. no cap, that's the entire move. 😌


🌸 DESCRIPTION 🌸

some components are ✨special✨ and can create an error stream on top of their regular message stream. like, they're doing the normal thing, but they also have a whole separate lane for when stuff goes sideways. main character energy, honestly.


πŸ‘‘ METHODS πŸ‘‘

πŸŽ€ error

an attribute containing the error chain.

by default, this is a chain of:

  • Message::Passing::Filter::Encoder::JSON
  • Message::Passing::Output::STDOUT

so out of the box your errors get JSON-encoded and then yeeted to STDOUT. simple, clean, slay. 🌈


πŸ’€ WARNINGS πŸ’€

bestie. listen to this section. i am not joking around here. πŸ™ˆ

πŸŒ€ 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!

here's the whole cursed cycle, spelled out: 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. it's giving snake eating its own tail. it's giving ouroboros but make it logging. do not do this. 😭

πŸ”€ 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. yeah. the error about the error becomes an error. we love a recursive meltdown fr fr. πŸ’€

all components which use error chains should be very careful to output data which they are entirely certain will be able to be encoded. like, be so sure. be more sure than that. be certain certain. 🫢


🌟 SPONSORSHIP 🌟

this module exists because of the wonderful people at Suretec Systems Ltd. <http://www.suretecsystems.com/> β€” they sponsored its development for their VoIP division called SureVoIP <http://www.surevoip.co.uk/> for use with the SureVoIP API β€” <http://www.surevoip.co.uk/support/wiki/api_documentation>

shoutout to the sponsors, we love a patron of the arts πŸŽ€βœ¨


see Message::Passing. (yes that's the whole thing. short and sweet, just like this section. go read that one, iykyk πŸ‘‘)


and that's the page!! this was built against perl v5.32.1 and the whole thing is dated 2021-11-09, from the User Contributed Perl Documentation. mwah, take care of your error chains, don't loop them, and go be the most well-behaved logging component you can be. periodt. πŸ’…βœ¨πŸ¦‹