I think you're checking the user input at the wrong point if you're relying on the DBI::errstr to tell you that user input is invalid.

From a security and usability stand point you should test your data long before you try and dump it into the database. I think the security part stands on it's own without further explanation.

The earlier you detect a problem the easier it tends to be to deal with it. What if this program routinely took 10 or 15 minutes to get to the point where the insert happens and DBI::errstr is populated? Your users will be upset.

Better options for detecting and reporting errors in web apps (in order of increasing ease of user interaction): (I actually skipped one option, but it relies on your application using a really good templating system and being one cgi with a lot of conditionally generated html: It's process the page on the server and return it with the offending fields highlighted and the error message above or below the field explaining the problem. The top of the page should declare that there is a problem and to pay attention to the indicators yadda yadda yadda.)

If you continue down the road you're on now are you really prepared to grep DBI::errstr for every partial error string that could be tossed from within the database?

--
Clayton

In reply to Re: The art of error handling by clscott
in thread The art of error handling by markjugg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.