I've offloaded all the file operations in my (increasingly rococo) content-management system into a separate module with an ad-hoc collection of other utilities. It's a nice little thing that caches and flocks, and all that, but i'd like to make it die more usefully.

At the moment i get messages along the lines of 'failed to append to /path/to/file: permission denied', or whatever. Which is fine, but it doesn't tell me much about what was going on at the time.

I'd really like the error messages to tell me which subroutine in which module was responsible for this foolish instruction. I can imagine various brute-force ways to do that, but they'd be horrible to maintain and wouldn't iterate properly.

The least-worst thing i've come up with is a sort of audit trail in which the start of every subroutine or other landmark pushes a note into a global variable (ick) recording the name of the sub and the values passed to it, if the necessary debug flag is present. Then a die_noisily() call could be used to reel off the concatenation if something goes wrong, or perhaps just the last three entries.

Is there a more elegant way to learn that i was in read_file() because get_record() was triggered by parse_template()?

Braces self for humiliating three-word answer.

btw, i know the debugger can do a lot of this, but i'd like something quick and generic for troubleshooting, and a lot of my clients have lobotomised virtual servers without command-line access.


In reply to dying() more informatively by thpfft

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.