This blog contains reflections and thoughts on my work as a software engineer

torsdag den 20. december 2007

Constant requiring explicit parsing == evil

I'm working on a project which includes the use of a service-enabled image uploader and imageviewer. The service defines a load of constants and properties in web.config which is fair enough.

However, when porting the assemblies to our local machines (we run all services, source and subsystems on our local machines to be able to work truly disconnected) we discovered a strange error while attempting to upload a test image to our service. Due to a lack of logging within the imageservice itself the cause of the error wasn't appareant at first but a quick review with the programmmer in charge of the imageservice reveiled that it was an issue with the configuration file.

One of the constants in the configuration defined a maximum height and width of an image being uploaded. If the size exceeded the maximums defined the upload would be rejected. The constants were defined in this way:

1024;768

What made the imageservice burp on our local machines had something to do with our regional settings which caused the configuration to try and interpret 1024;768 as an integer.

With our retrospective cap well in place what could / should have we done better to avoid such a problem from occuring?

- Never define constants which require explicit parsing to become valid
- If you decide to do provide detailed logging before and after the parsing occurs
- Take into account within your software that machine regional settings are - well, machine dependent ;o)

Ingen kommentarer: