Ask Reuben

It’s The Environment, Stupid

Why does a program run with Direct Connection but not when run via Genero Application Server, or vice versa ?

Why does a program run with GDC but not through a Browser, or vice versa ?

Why does a program compile or run from the command line but not via Genero Studio, or vice versa ?

Why does a program run on this server but not on this server ?

Why does a program run with this version but not with this version ?

The title for this weeks article is a snowclone of the phrase It’s The Economy, Stupid., a phrase that was coined during Bill Clinton’s election campaign and has come to be repeated in popular culture with the word “economy” substituted for another word.  It is a phrase that enters my head when I take something that I know works, move it or change it in some way to use something new, and then hit an initially baffling error.

In such circumstances it is typically because an environment variable is not set correctly.  The saying “It’s The Environment, Stupid” helps make me make sure that I check that Environment Variables have the value I expect them to be.  The risque nature of the phrase helping it stick in my mind and execute some steps quickly to compare environments before I go off down the wrong path.

It also comes into my thought process when I see a support issue when the user says that their programs works in one environment and not the other, and I can typically get them on the right track by checking environment variables.

I hit such an error recently.  I was looking at some new functionality in v5 of Genero Report Writer.  In my configuration to test using GDC I had checked the appropriate Environment Set to set GREDIR at a 5.00 Genero Report Writer installation, but I had not checked the same Environment Set in my configuration to test using a Browser.  As a result I got a runtime error when running a program in a Browser when I knew that program worked in the GDC…

The key debug technique is to have the ability to execute the following command (or your Operating Systems equivalent) …

RUN "env | sort > /tmp/yourname.env"

… in both the system that works and the system that does not work, and to then do a diff or compare the output of the two files.  This will typically tell you that an environment variable has a different value or is missing.

In my case, this technique gave me output of …


33c76,86 
< GREDIR=/Applications/fourjs/gre/5.00.00 
--- 
> GREDIR=/Applications/fourjs/gre/4.01.09

… and there was a D’oh! moment.

More often than not, it is the PATH or LD_LIBRARY_PATH or equivalent environment variables that are not set.

If you have an initialisation function that every program runs at startup, I would investigate how you can come up with a mechanism to execute a command similar to this at startup, perhaps if an environment variable is set or a command line argument is specified.  Make sure this is done before any attempted connection to a database or front-end so that this technique can be used for database and front-end issues.  This will save you some time in the future.