alexgorbatchev

Thursday, April 3, 2014

Grails Gotchas: Configuration Files and GStrings

Configuration Files

Be careful in defining configuration information using double quotes, because if the value you are attempting to assign contains a dollar sign ($), grails will see that as a variable and attempt to substitute the letters/words following the dollar sign with variable information for those letters/words. While this situation probably only presents itself with passwords, I always use single quotes defining information in the configuration files, unless I explicitly want to inject variable data into a configuration attribute, so there is no confusion.

For example, the following error-causing configuration
datasource {
  ...
  password = "Thi$i$Secure"
  ...
}
would probably result in password = 'Thi', unless you defined an i or Secure variable somewhere else in the configuration file, in which case, you would assign the result of evaluating that information too.

Instead, I would suggest that you always specify your configuration information in single quotes
datasource {
  ...
  password = 'Thi$i$Secure'
  ...
}

For sake of completeness, you could alternatively escape the dollar sign ($)
datasource {
  ...
  password = "Thi\$i\$Secure"
  ...
}
however, this leaves the possibility for errors that may not be easy to spot. Especially, if you have an externalized config and this error arises in production.

Wednesday, March 12, 2014

Webstorm and Karma in Ubuntu 12 LTS

If you are attempting to run Karma unit tests from Webstorm in Ubuntu 12LTS you may run into the following error:
Cannot start Chrome
 Can not find the binary google-chrome
 Please set env variable CHROME_BIN
Attempting to export CHROME_BIN=/usr/bin/chromium-browser worked great for running karma from the command line, but did not fix my issue when running it from within Webstorm, so after a bit of searching I found that you can add environment variables to webstorm by editing the Run/Debug Configurations for Karma:
  1. Under Run > Edit Configurations...
  2. Select Karma > karma.conf.js 
  3. Add the Environment Variables:
    CHROME_BIN=<path to chromium-browser>
    • To find the location of chromium-browser:
      which chromium-browser