S h o r t S t o r i e s

// Tales from software development

A fresh pair of eyes…

leave a comment »

My first week on a new assignment and the first task I’m given is to look at a bug that’s been around for a few weeks that no one has made any sigificant progress on. The bug report looked like this:

Order Notes – Error on adding a note

2008-09-10: Ian

Go to search page
Search for an order number
Scroll to the bottom of the order and click the Add Note option
Enter some text for the note and click the Save button.

Expected outcome: Note saved

Actual outcome: An error occurred, please contact IT

2008-09-15: Richard

This bug is now resolved. Configurational issues in the test environment.

2008-09-16: Ian

Re-opened – bug still appears in test environment.

2008-09-19: Richard

Now fixed with latest deployment to test environment.

2008-09-22: Ian

Re-opened – bug still manifests.

2008-09-22: Paul

Issue is environmental. A script needs to be run to clear database schema locks on each deployment. Once script has been run this bug no longer occurs. Please ensure that this script is part of the deployment.

2008-09-23: Jim

I have successfully added notes without any changes to the environment. Perhaps a change in database permissions elsewhere has resolved the bug ? Please re-test.

2008-10-08: John

Error is still occurring. Looking at the code, the code most likely to be failing is the call to GetLoggedInUser() and GetLoggedInAccount(). We should investigate this code.

I chatted to one of the guys who had spent some time debugging this error and he told me that the bug was intermittant and that it generally didn’t manifest itself when the code was run in a debugger. So, I decided my first line of attack was to track down where the error message was being issued and simply look at the code to see if there was any obvious reason for an error to occur there.

Fortunately, the error message was hard coded in the source code and I could see that it was in the catch block associated with a try block with 5 lines of code:

User user = GetLoggedInUser()
note += "[" +  user.FirstName.Substring(0, 1) + user.LastName.Substring(0,3) + "] ";
note += "\r\n";
Response.Redirect("/Orders/ViewOrder.aspx?order=" + order.OrderNumber.ToString());

What immediately struck me were the two calls to the Substring() method in the second line. I doubted that there was any rule to enforce a FirstName of at least one character and a LastName of at least three characters. So, this code was going to fail whenever the FirstName was blank and the LastName was blank or less than three characters. 

I spent a few hours configuring the code so that it would run on my machine against the data in the test environment and confirmed that the Substring() calls were causing the error. The userid that the testers were using had blank FirstName and LastName properties and the following exception occurred:

Index and length must refer to a location within the string.
Parameter name: length

Sometimes it just needs a fresh pair of eyes to see the blindingly obvious…


Written by Sea Monkey

October 16, 2008 at 9:00 pm

Posted in Debugging

Tagged with

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: