Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Error Reporting from Module

by tobyink (Canon)
on Oct 09, 2019 at 11:55 UTC ( [id://11107236]=note: print w/replies, xml ) Need Help??


in reply to Error Reporting from Module

I've looked at your code. My recommendation would be to replace things like this:

carp "xyz"; return;

With this:

return $self->log_error("xyz");

And then define this method:

sub log_error { carp $_[1]; return; }

Then anybody who needs different error handling can subclass your class.

use Subclass::Of "WebService::Discord::Webhook", -as => "MyWebhook", -methods => [ error_log => sub { my ($self, $message) = @_; # alternative error handling here }, ]; ...; my $webhook = MyWebhook->new(...);

If you have different severities of error message, you may wish to provide multiple methods like log_unrecoverable_error and log_recoverable_error. Whatever makes sense to you.

Document these methods, how and when they will be called, etc. This way, people subclassing your module will know that they're not some kind of internal thing that might disappear in the next release, but are a supported part of the API.

Replies are listed 'Best First'.
Re^2: Error Reporting from Module
by Fletch (Bishop) on Oct 09, 2019 at 13:24 UTC

    If you go that route you might look at Log::Log4perl or Log::Dispatch rather than reinventing existing wheels.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      I've always found those sorts of things are more oriented around application-level logging rather than a module reporting errors to its caller, but my experience with them is pretty minimal.

        Very valid point; you then tie your users into said framework. I've grown to like L4p but then I've been recently mucking with stuff in spark JVM land from clojure and it's pretty much a given that something will have set up sl4j (or some other compatible logging mechanism) and so using that is just the way things are done and that's probably coloring my thinking.

        The cake is a lie.
        The cake is a lie.
        The cake is a lie.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11107236]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 17:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found