Need help in understanding error reporting - popup vs log

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
ZLA
Commodore (COMO)
Commodore (COMO)
Posts: 496
Joined: Fri Mar 13, 2009 2:55 pm

Need help in understanding error reporting - popup vs log

Post by ZLA » Mon Aug 24, 2009 1:08 pm

I have customized code that generates an email with an attachment when an order is updated to a custom order status. I had a bug in my code that caused IE to popup with an error saying "Could not find a part of the path..." which I quickly fixed.

What I don't understand is why the error and its details didn't get reported to the error log. In Admin/Orders/Default.aspx.cs BatchButton_Click, I have

Code: Select all

   SG_OrderHelper sgOrder = new SG_OrderHelper(order);
   sgOrder.SendVendorNotifications();
In SG_OrderHelper, I have:

Code: Select all

public class SG_OrderHelper
{
   ... snip ...

   public static string CreateXMLOrderFile(int orderId, int vendorId, int orderNumber)
   {
   ... snip ...

      DirectoryInfo di;
      di = new DirectoryInfo(HttpContext.Current.Server.MapPath("~/App_Data/XmlFiles"));

   ... snip ...
   }

   ... snip ...
}
which caused the error.

Can someone please explain why the error wasn't trapped in the error log and why the error message is displayed as a browser dialog? Thanks in advance.

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Need help in understanding error reporting - popup vs log

Post by AbleMods » Mon Aug 24, 2009 1:56 pm

ZLA wrote:I had a bug in my code that caused IE to popup with an error saying "Could not find a part of the path..." which I quickly fixed.....
Usually errors that result in an IE popup are client-side errors. If so, the server-side code never saw the error and thus the Able error logging could not catch it to log.

Plus you've developed a custom helper class. You'll need to implement your own try-catch functionality and log the errors yourself. Able code and classes have their own try-catch functionality that logs the error using the ErrorLogDataSource. You'll need to manually implement this in your own classes as well or rely on global.asax to trap/log the error for you. I prefer implementing it on my own in each class so my error logs can be more specific to the section of code being executed.

Client-side errors can be a huge pain to troubleshoot. I ran into several last week working on a gridview control that kept throwing "Object not set to...." during the AJAX postbacks. the IE popup wouldn't tell me WHERE the stupid error was, so I wound up having to walk the code in the debugger line-by-line until to finally threw the error. Finally figured out I wasn't saving and restoring session state correctly.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

ZLA
Commodore (COMO)
Commodore (COMO)
Posts: 496
Joined: Fri Mar 13, 2009 2:55 pm

Re: Need help in understanding error reporting - popup vs log

Post by ZLA » Mon Aug 24, 2009 2:16 pm

Thanks for the info Joe. Based on what you say, it appears that any error in the App_Code directory are handled by the calling code or within the called class method (for example, bool showTaxLineItems = (TaxHelper.GetTaxProvider().InvoiceDisplay == TaxInvoiceDisplay.LineItem);). ErrorLogDataSource is never called by any of the classes in App_Code. There are a few try catch lines to prevent errors but they don't report anything.

Therefore, the calling code in the admin page must be reporting the bubbled up error as a popup. My code is pure server side. The issue may be that the admin page's BatchButton is inside an ajax UpdatePanel.

Do you (or AC) know if that would cause the observed behavior?

I may have to reproduce the problem locally and walk through it as you suggested just to understand why the Admin Orders page doesn't record my error in the error log.

afm
Captain (CAPT)
Captain (CAPT)
Posts: 339
Joined: Thu Nov 03, 2005 11:52 pm
Location: Portland, OR
Contact:

Re: Need help in understanding error reporting - popup vs log

Post by afm » Mon Aug 24, 2009 4:01 pm

ASP.NET Ajax has its own error handler which normally propogates error messages to the client. See

http://www.asp.net/AJAX/documentation/l ... Panel.aspx

Because they are handled by ASP.NET Ajax, they never reach the Application_Error method in globabl.asax, which would normally log them.

As Joe mentioned, you can catch exceptions and handle them yourself (including adding them to the log).

It is fairly standard practice (at least amoung .NET practitioners) to not catch exceptions in low level, utility methods such as those in the App_Code directory. Partly because the low level method typcially does not know why it is doing whatever it does, so it would not know how to recover.
Andy Miller
Structured Solutions

Shipper 3 - High Velocity Shipment Processing

ZLA
Commodore (COMO)
Commodore (COMO)
Posts: 496
Joined: Fri Mar 13, 2009 2:55 pm

Re: Need help in understanding error reporting - popup vs log

Post by ZLA » Mon Aug 24, 2009 4:53 pm

afm wrote:It is fairly standard practice (at least amoung .NET practitioners) to not catch exceptions in low level, utility methods such as those in the App_Code directory. Partly because the low level method typcially does not know why it is doing whatever it does, so it would not know how to recover.
I agree. I wasn't concerned about not catching the errors but to logging them. Any idea if there's a general way to catch ajax errors for logging so as not to lose the details?

Thanks.

afm
Captain (CAPT)
Captain (CAPT)
Posts: 339
Joined: Thu Nov 03, 2005 11:52 pm
Location: Portland, OR
Contact:

Re: Need help in understanding error reporting - popup vs log

Post by afm » Mon Aug 24, 2009 5:19 pm

The link I included has some ideas, and there are more if you google "ASP.NET Ajax error handling".
Andy Miller
Structured Solutions

Shipper 3 - High Velocity Shipment Processing

Post Reply