Wednesday, June 20, 2007

My client fell through an FOPEN() hole

I got a call from a relatively new online reseller client whose backoffice system was written (by someone else) in VFP. The orders they receive from their Amazon store have to be updated with shipping information and tracking numbers in Amazon's system. This is done when they enter the tracking number into a VFP form and click Save: the form code creates an XML order fulfillment file in a drive-mapped server folder, where it is picked up and sent to Amazon by an automated process.

They were alerted recently to the fact that their order fulfillments were not reaching Amazon, so I dug into the old code to see what the matter might be. Here is the essential code that saves the generated XML into a file:

lfhan = FCREATE(this.xmlfile)
=FWRITE(lfhan,this.xmlstring)
=FCLOSE(lfhan)

Assuming that this.xmlfile = "x:\feeds\orders\_1x3d8sfx.xml" can you guess the problem?

After looking at those three lines of code for a couple of minutes, I realized that the problem could be a missing drive mapping to drive "x" on the computer running the process. Because the code does not check to see if "lfhan" = -1 (problem creating file), the next line calls FWRITE (and doesn't check the number of characters written, which is zero in this case), then FCLOSE does nothing (since there is nothing to close).

No errors show up to the user and weeks pass before the problem comes to the surface.

Because such a complex, automated system was brought to its knees by a simple programmer oversight, I've resolved to "get it right" the first time in my work by coding in anticipation of errors instead of coding by oversight.

0 Comments:

Post a Comment

<< Home