Browse Source

Catch misconfigured locale settings

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@59655 15284696-431f-4ddb-bdfa-cd5b030d7da7
Maris Nartiss 11 years ago
parent
commit
68923c9a13
1 changed files with 10 additions and 1 deletions
  1. 10 1
      lib/init/grass.py

+ 10 - 1
lib/init/grass.py

@@ -789,7 +789,16 @@ def set_language():
         # Language override is disabled (system language specified)
         # As by default program runs with C locale, but users expect to
         # have their default locale, we'll just set default locale
-        locale.setlocale(locale.LC_ALL, '')
+        try:
+            locale.setlocale(locale.LC_ALL, '')
+        except locale.Error, e:
+            # If we get here, system locale settings are terribly wrong
+            # There is no point to continue as GRASS/Python will fail
+            # in some other unpredictable way.
+            print "System locale is not usable. It indicates misconfigured environment."
+            print "Reported error message: %s" % e
+            sys.exit("Fix system locale settings and then try again.")
+        
         language, encoding = locale.getdefaultlocale()
         if not language:
             warning("Default locale settings are missing. GRASS running with C locale.")