ErrorHandling

by Donovan Chandler

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
— Martin Golding

Error log layout

Error log layout

Overview

Your code is at some point going to fail you and your users. Some people don’t bother to trap for errors while others check every single action. This module is for the rest of us – those who want moderate functionality without being overburdened with extra script steps and decisions.

The module provides two primary scripts; one for logging errors to a table, and another for displaying errors to the user. Much of the power in this module is in the conventions it proposes.

Guiding Assumptions

  • Error handling should require very little overhead on the developer’s part. It should be habitual.
  • Error handling should not distract from the overall goals of the code.
  • Errors should be logged as close to the event as possible. This allows us to gather better diagnostic information and prevents other errors from interfering.
  • Errors should be reported as close to the initiating action as possible. This allows errors from a generic subscript to bubble up to the button script, for example, where it can be customized for the context.
  • Any particulars about an error (how to abort, message to the user, workflow decisions, etc) should be handled where the affected logic resides. In other words, it should be transparent and customizable for the developer – not buried in a subscript somewhere.

How It’s Used (In a Nutshell)

  • Scripts are wrapped in a single-pass loop so that it’s easy to skip straight to error handling and clean-up.
  • Error codes are always posted to $_error.
  • If you want to display a message to the user, post it to $_error_message.
  • All scripts check for and log errors just before exiting.
  • User-facing scripts check for error messages to display to the user. A subscript may declare an error message, but it passes the message up the chain for the user-facing script to use or modify.
  • When presented with an error dialog, the user can choose to email a bug report to the admin.
  • All errors are logged to a table along with diagnostic information.

Integration

See the README script for installation instructions.

Release History

  • 1.0.0 – 11/27/13 – Initial release
  • 1.0.1 – 11/30/13 – Respects open records
  • 1.0.2 – 12/04/13 – Error dialog allows user to press “Report” and email details to admin
  • 1.0.3 – 12/04/13 – Upgraded ParamConverter to 1.0.2; Enhanced control over error display
  • 1.1.0 – 08/19/14 – Restore original capture state; Don’t show dialogs when Error Capture is set to On

Download

Download the latest version on GitHub.

The demo below provides additional examples that demonstrate more robust parameter parsing. The additional examples use the Six Fried Rice parameter format, so they also employ the wrapper scripts in this module.

ErrorHandling 1.0.3 Enhanced

5 responses to “ErrorHandling”

  1. dansmith65 says:

    Lately I’ve been working on both Error Handling and Logging, so this module sparks my interest.

    I like how you built email notification into this module. I was planning on adding this to mine, but was thinking of implementing it via a server scheduled task and having it email based on matching a specified find criteria. I also like your use of whitespace, especially how you’ve delineated your single-pass loop.

    Why use the underscore prefix on all $local and $$global variables?

    Is there a bug in the “. error . setting . go to utility layout” script, in the Set Variable step after Else? From what I understand of the module, it should be setting $_error_message variable, not $_error.

    I know the “. error . setting . go to utility layout” script is supposed to be modified as needed by the user, but for anybody implementing this module, here is a possible scenario that may need to be handled by this script:
    – if the current record is open, going to a new layout will commit the record. If you disable commits via a layout trigger, then this script (which runs with triggers disabled) would bypass that layout trigger and commit the record before switching layouts.
    – a work-around in this case is to open a new window to create the log entry

    A few considerations for the “. error . log” script:
    – after calling the “. error . setting . go to utility layout” script, you should check for a sub-script error before creating a record
    – since you use a sub-script to go to a layout, I think you should use another sub script to return from that layout (in case the go to layout script needs to open a new window)

  2. Donovan Chandler says:

    Thanks for the detailed feedback Dan. I’ll be posting v1.0.1 including many of your recommendations soon.

    You’ve obviously put a lot of thought into the topic of error handling and I appreciate the dialog especially where our approaches may differ. I’ll write a more detailed response after I’ve worked on and posted the revised version.

    It pains me how messy the implementation looks without any helper functions, so I hope to post an alternative demo soon that includes them. The scripts will be much more concise.

  3. Donovan Chandler says:

    Dan, I incorporated much of your feedback.

    I like the idea of sending emails from the server, especially if there’s anything special like HTML formatting involved. But I liked the simplicity of using the client for the purpose of this module. I also like how they can edit the message. The technical details will the in the log record, but the user could provide some helpful info about their workflow. Come to think of it, I’ve just added some text to the email prompting the user to describe what happened.

    I like seeing clearly where the single-pass loop starts and ends, but I was curious how others would react to it. Nice that someone else appreciates it too.

    The $_underscores are just a carry-over from the FOCUS framework where we decided it made variables more readable. This module is an attempt to bridge our internal conventions with others’ so I’m still negotiating some of those conflicts.

    Good catch on “. error . setting . go to utility layout”. It’s fixed in 1.0.1.

    Another issue I found is that the script results are malformed if there’s no $_error value. So I’ve added “$_error = 0” to the top of each script.

    I hadn’t considered open records. I went with what I think is the safest and simplest approach, which is to just open a new window by default before creating the log record. The window creation is managed by a preference script. Any script that calls it will check for a new window and close it if necessary. I prefer that to having two separate subscripts coupled to each other.

    I haven’t had much time to dig into your error handling file yet, but I’m looking forward to it. I’m intrigued so far by the idea of providing a wrapper function for packaging the error data. I’m still thinking through some of the ramifications of that though.

  4. […] ErrorHandling Query Builder […]

  5. God had other plans for me, he said.. President, we urge you to fulfill your commitment to require GE labeling and to add the United States of America to the list of 64 nations that have already given their consumers the right to know what is in their food.
    cheap toms shoes,cheap toms,cheap toms shoe,discount toms shoes,discount toms,toms shoes,buy toms,toms shoes for sale,cheap toms shoes for sale,toms shoes outlet,toms shoes for sale,toms shoes,toms shoes outlet,toms shoes for sale,toms shoes cheap,toms shoes online,toms shoes for sale,cheap toms shoes for sale,toms shoes for cheap,pre order toms shoes,pre order cheap toms shoes,cheap toms shoes,buy cheap toms shoes,authentic toms shoes,authentic cheap toms shoes,buy toms shoes,buy cheap toms shoes,order toms shoes,order cheap toms shoes,toms shoes online,buy toms shoes online,toms shoes 2015,cheap toms shoes 2015 [url=http://www.actionwildlife.org/news/buytomsshoes/index.html]cheap toms shoes,cheap toms,cheap toms shoe,discount toms shoes,discount toms,toms shoes,buy toms,toms shoes for sale,cheap toms shoes for sale,toms shoes outlet,toms shoes for sale,toms shoes,toms shoes outlet,toms shoes for sale,toms shoes cheap,toms shoes online,toms shoes for sale,cheap toms shoes for sale,toms shoes for cheap,pre order toms shoes,pre order cheap toms shoes,cheap toms shoes,buy cheap toms shoes,authentic toms shoes,authentic cheap toms shoes,buy toms shoes,buy cheap toms shoes,order toms shoes,order cheap toms shoes,toms shoes online,buy toms shoes online,toms shoes 2015,cheap toms shoes 2015[/url]

Leave a Reply

Your email address will not be published. Required fields are marked *