Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Perl Catalyst and DBIx::Class best practice question.

by perl_helper (Initiate)
on Dec 12, 2008 at 10:40 UTC ( #729906=perlquestion: print w/ replies, xml ) Need Help??
perl_helper has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I'm currently developing a Catalyst application using DBIx::Class as the ORM. I'm just wondering about the best practice for exception handling for the DBIx::Class.

Since I'm still in QA, currently I'm having a lot of that purple catalyst error screen whenever I did something wrong with the DBIx::Class(e.g creating a record with the wrong column name, or undefined as a parameter when searching for a record).

Of course we can't have that purple screen when we move it to production, so I'm just wondering if any monks here can give me an advice on how to tackle this problem?. I know that wrapping the DBIx::Class call with eval and catching it is one way, but it could be very exhaustive since there is so many places where we want to retrieve a record or create one.

Is there a more elegant solution to this?. I tried googling it as well as searching it in cpan but found no elegant solution.

Thanks for the help and advice that you can give me. Any link to a documentation will be much appreciated.

Thanks,
perl_helper.

Comment on Perl Catalyst and DBIx::Class best practice question.
Re: Perl Catalyst and DBIx::Class best practice question.
by jeffa (Chancellor) on Dec 12, 2008 at 15:49 UTC

    "Of course we can't have that purple screen when we move it to production ..."

    Just use a different web server configuration (Apache?) for your production server that overrides the stock error page and displays a friendly "Contact admin" splash page instead. The real error should be logged automatically by the web server.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: Perl Catalyst and DBIx::Class best practice question.
by dragonchild (Archbishop) on Dec 12, 2008 at 15:57 UTC
    Since I'm still in QA, currently I'm having a lot of that purple catalyst error screen whenever I did something wrong with the DBIx::Class(e.g creating a record with the wrong column name, or undefined as a parameter when searching for a record).

    This sounds like you're not validating your input prior to passing it to your model. If so, then that's the root issue. And, frankly, it's going to be a root issue for a lot more than the PSOD.


    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: Perl Catalyst and DBIx::Class best practice question.
by Your Mother (Canon) on Dec 12, 2008 at 20:52 UTC

    There is no need (90%+ of the time) for doing manual exception catching in Catalyst. It's already doing it for you. The debug screen is showing the caught (didn't crash the app) but unhandled (the code didn't bother to deal with them) errors.

    In your end block if there were exceptions you'll find them stacked up in $c->error.

    my @error = @{ $c->error }; # Add a new error. $c->error('Something bad happened'); # Clear the errors after doing something with them # like putting them in the stash for pretty printing # them in a template. $c->clear_errors() # This is equivalent to running $c->error(0);
    There are a couple of Error handling packages to do some of the more repetitive mechanical parts of it and even do configured email alerts and such. Check the CPAN or the Cat list.

Re: Perl Catalyst and DBIx::Class best practice question.
by trwww (Priest) on Dec 13, 2008 at 19:51 UTC
      Thanks for all the advices and recommendations, I'll definitely going to do more checks. Thanks everyone.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://729906]
Approved by Corion
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2014-09-16 15:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (33 votes), past polls