Ver Fonte

[desktop] Log all caught naked "except:" blocks

Erick Tryzelaar há 10 anos atrás
pai
commit
249ff26

+ 1 - 0
desktop/core/src/desktop/api.py

@@ -175,6 +175,7 @@ def massaged_documents_for_json(documents, user):
     try:
     try:
       url = document.content_object.get_absolute_url()
       url = document.content_object.get_absolute_url()
     except:
     except:
+      LOG.exception('failed to get absolute url')
       # If app of document is disabled
       # If app of document is disabled
       url = ''
       url = ''
     docs[document.id] = massage_doc_for_json(document, user, url)
     docs[document.id] = massage_doc_for_json(document, user, url)

+ 1 - 0
desktop/core/src/desktop/auth/backend.py

@@ -62,6 +62,7 @@ def load_augmentation_class():
     LOG.info("Augmenting users with class: %s" % (klass,))
     LOG.info("Augmenting users with class: %s" % (klass,))
     return klass
     return klass
   except:
   except:
+    LOG.exception('failed to augment class')
     raise ImproperlyConfigured("Could not find user_augmentation_class: %s" % (class_name,))
     raise ImproperlyConfigured("Could not find user_augmentation_class: %s" % (class_name,))
 
 
 _user_augmentation_class = None
 _user_augmentation_class = None

+ 3 - 0
desktop/core/src/desktop/lib/django_util.py

@@ -41,6 +41,8 @@ import desktop.lib.thrift_util
 from desktop.lib import django_mako
 from desktop.lib import django_mako
 from desktop.lib.json_utils import JSONEncoderForHTML
 from desktop.lib.json_utils import JSONEncoderForHTML
 
 
+LOG = logging.getLogger(__name__)
+
 # Values for template_lib parameter
 # Values for template_lib parameter
 DJANGO = 'django'
 DJANGO = 'django'
 MAKO = 'mako'
 MAKO = 'mako'
@@ -327,6 +329,7 @@ def get_app_nice_name(app_name):
   try:
   try:
     return desktop.appmanager.get_desktop_module(app_name).settings.NICE_NAME
     return desktop.appmanager.get_desktop_module(app_name).settings.NICE_NAME
   except:
   except:
+    LOG.exception('failed to get nice name for app %s' % app_name)
     return app_name
     return app_name
 
 
 class TruncatingModel(models.Model):
 class TruncatingModel(models.Model):

+ 4 - 0
desktop/core/src/desktop/lib/thrift_util_test.py

@@ -22,6 +22,8 @@ import threading
 import time
 import time
 import unittest
 import unittest
 
 
+LOG = logging.getLogger(__name__)
+
 gen_py_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "gen-py"))
 gen_py_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "gen-py"))
 if not gen_py_path in sys.path:
 if not gen_py_path in sys.path:
   sys.path.insert(1, gen_py_path)
   sys.path.insert(1, gen_py_path)
@@ -78,6 +80,7 @@ class SimpleThriftServer(object):
                                        TBinaryProtocolFactory())
                                        TBinaryProtocolFactory())
       server.serve()
       server.serve()
     except:
     except:
+      LOG.exception('failed to start thrift server')
       sys.exit(1)
       sys.exit(1)
 
 
   def _ensure_online(self):
   def _ensure_online(self):
@@ -92,6 +95,7 @@ class SimpleThriftServer(object):
         ping_s.close()
         ping_s.close()
         return
         return
       except:
       except:
+        LOG.exception('failed to connect to child server')
         _, status = os.waitpid(self.pid, os.WNOHANG)
         _, status = os.waitpid(self.pid, os.WNOHANG)
         if status != 0:
         if status != 0:
           logging.info("SimpleThriftServer child process exited with %s" % (status,))
           logging.info("SimpleThriftServer child process exited with %s" % (status,))

+ 3 - 0
desktop/core/src/desktop/log/formatter.py

@@ -20,6 +20,7 @@ import os
 
 
 from pytz import timezone, datetime
 from pytz import timezone, datetime
 
 
+LOG = logging.getLogger(__name__)
 
 
 class Formatter(logging.Formatter):
 class Formatter(logging.Formatter):
   def formatTime(self, record, datefmt=None):
   def formatTime(self, record, datefmt=None):
@@ -27,9 +28,11 @@ class Formatter(logging.Formatter):
       tz = timezone(os.environ['TZ'])
       tz = timezone(os.environ['TZ'])
       ct = datetime.datetime.fromtimestamp(record.created, tz=tz)
       ct = datetime.datetime.fromtimestamp(record.created, tz=tz)
     except:
     except:
+      LOG.exception('failed to format time')
       try:
       try:
         ct = datetime.datetime.fromtimestamp(record.created)
         ct = datetime.datetime.fromtimestamp(record.created)
       except:
       except:
+        LOG.exception('failed to format time')
         # Fallback to original.
         # Fallback to original.
         return super(Formatter, self).formatTime(record, datefmt=datefmt)
         return super(Formatter, self).formatTime(record, datefmt=datefmt)
 
 

+ 1 - 0
desktop/core/src/desktop/middleware.py

@@ -438,6 +438,7 @@ class HtmlValidationMiddleware(object):
       fn = urlresolvers.resolve(request.path)[0]
       fn = urlresolvers.resolve(request.path)[0]
       fn_name = '%s.%s' % (fn.__module__, fn.__name__)
       fn_name = '%s.%s' % (fn.__module__, fn.__name__)
     except:
     except:
+      LOG.exception('failed to resolve url')
       fn_name = '<unresolved_url>'
       fn_name = '<unresolved_url>'
 
 
     # Write the two versions of html out for offline debugging
     # Write the two versions of html out for offline debugging

+ 5 - 2
desktop/core/src/desktop/migrations/0007_auto__add_documentpermission__add_documenttag__add_document.py

@@ -1,4 +1,5 @@
 # encoding: utf-8
 # encoding: utf-8
+import logging
 import datetime
 import datetime
 from south.db import db
 from south.db import db
 from south.v2 import SchemaMigration
 from south.v2 import SchemaMigration
@@ -6,6 +7,8 @@ from django.db import connection, models
 
 
 from desktop.models import Document
 from desktop.models import Document
 
 
+LOG = logging.getLogger(__name__)
+
 class Migration(SchemaMigration):
 class Migration(SchemaMigration):
 
 
     def forwards(self, orm):
     def forwards(self, orm):
@@ -85,7 +88,7 @@ class Migration(SchemaMigration):
             # Removing M2M table for field groups on 'DocumentPermission'
             # Removing M2M table for field groups on 'DocumentPermission'
             db.delete_table('desktop_documentpermission_groups')
             db.delete_table('desktop_documentpermission_groups')
         except:
         except:
-            pass
+            LOG.exception('failed to delete tables')
 
 
         # Remove new m2m fields
         # Remove new m2m fields
         try:
         try:
@@ -95,7 +98,7 @@ class Migration(SchemaMigration):
             # Removing M2M table for field groups on 'DocumentPermission'
             # Removing M2M table for field groups on 'DocumentPermission'
             db.delete_table('documentpermission_groups')
             db.delete_table('documentpermission_groups')
         except:
         except:
-            pass
+            LOG.exception('failed to delete tables')
 
 
         # Deleting model 'DocumentTag'
         # Deleting model 'DocumentTag'
         db.delete_table('desktop_documenttag')
         db.delete_table('desktop_documenttag')

+ 4 - 2
desktop/core/src/desktop/migrations/0008_documentpermission_m2m_tables.py

@@ -1,8 +1,10 @@
 # -*- coding: utf-8 -*-
 # -*- coding: utf-8 -*-
+import logging
 from south.db import db
 from south.db import db
 from south.v2 import SchemaMigration
 from south.v2 import SchemaMigration
 from django.db import connection, models
 from django.db import connection, models
 
 
+LOG = logging.getLogger(__name__)
 
 
 class Migration(SchemaMigration):
 class Migration(SchemaMigration):
 
 
@@ -29,7 +31,7 @@ class Migration(SchemaMigration):
             # Only want to make sure that these tables exist.
             # Only want to make sure that these tables exist.
             # The previous migration should create these tables,
             # The previous migration should create these tables,
             # but it has been refactored to do so.
             # but it has been refactored to do so.
-            pass
+            LOG.exception('failed to create tables')
 
 
     def backwards(self, orm):
     def backwards(self, orm):
         pass
         pass
@@ -113,4 +115,4 @@ class Migration(SchemaMigration):
         }
         }
     }
     }
 
 
-    complete_apps = ['desktop']
+    complete_apps = ['desktop']

+ 5 - 0
desktop/libs/hadoop/src/hadoop/fs/exceptions.py

@@ -16,10 +16,13 @@
 # limitations under the License.
 # limitations under the License.
 
 
 import json
 import json
+import logging
 
 
 from desktop.lib.exceptions import StructuredException
 from desktop.lib.exceptions import StructuredException
 from desktop.lib.rest.http_client import RestException
 from desktop.lib.rest.http_client import RestException
 
 
+LOG = logging.getLogger(__name__)
+
 
 
 class PermissionDeniedException(StructuredException):
 class PermissionDeniedException(StructuredException):
   def __init__(self, msg, orig_exc=None):
   def __init__(self, msg, orig_exc=None):
@@ -38,5 +41,7 @@ class WebHdfsException(RestException):
       self.server_exc = json_body['exception']
       self.server_exc = json_body['exception']
       self._message = "%s: %s" % (self.server_exc, json_body['message'])
       self._message = "%s: %s" % (self.server_exc, json_body['message'])
     except:
     except:
+      LOG.exception('failed to parse remote exception')
+
       # Don't mask the original exception
       # Don't mask the original exception
       self.server_exc = None
       self.server_exc = None

+ 3 - 3
desktop/libs/hadoop/src/hadoop/fs/fsutils.py

@@ -39,7 +39,7 @@ def do_overwrite_save(fs, path, data, encoding):
             try:
             try:
                 fs.remove(path_dest)
                 fs.remove(path_dest)
             except:
             except:
-                pass
+                logger.exception('failed to remove %s' % path_dest)
             raise e
             raise e
 
 
     _do_overwrite(fs, path, copy_data)
     _do_overwrite(fs, path, copy_data)
@@ -74,13 +74,13 @@ def _do_overwrite(fs, path, copy_data):
     try:
     try:
         fs.do_as_superuser(fs.chmod, path_dest, stat_module.S_IMODE(cur_stats['mode']))
         fs.do_as_superuser(fs.chmod, path_dest, stat_module.S_IMODE(cur_stats['mode']))
     except:
     except:
-        logging.warn("Could not chmod new file %s to match old file %s" % (path_dest, path), exc_info=True)
+        logging.exception("Could not chmod new file %s to match old file %s" % (path_dest, path))
         # but not the end of the world - keep going
         # but not the end of the world - keep going
 
 
     try:
     try:
         fs.do_as_superuser(fs.chown, path_dest, cur_stats['user'], cur_stats['group'])
         fs.do_as_superuser(fs.chown, path_dest, cur_stats['user'], cur_stats['group'])
     except:
     except:
-        logging.warn("Could not chown new file %s to match old file %s" % (path_dest, path), exc_info=True)
+        logging.exception("Could not chown new file %s to match old file %s" % (path_dest, path))
         # but not the end of the world - keep going
         # but not the end of the world - keep going
 
 
     # Now delete the old - nothing we can do here to recover
     # Now delete the old - nothing we can do here to recover

+ 1 - 1
desktop/libs/hadoop/src/hadoop/fs/hadoopfs.py

@@ -293,7 +293,7 @@ class Hdfs(object):
             chunk = src.read(chunk_size)
             chunk = src.read(chunk_size)
           LOG.info(_('Copied %s -> %s.') % (local_src, remote_dst))
           LOG.info(_('Copied %s -> %s.') % (local_src, remote_dst))
         except:
         except:
-          LOG.error(_('Copying %s -> %s failed.') % (local_src, remote_dst))
+          LOG.exception(_('Copying %s -> %s failed.') % (local_src, remote_dst))
           raise
           raise
       finally:
       finally:
         src.close()
         src.close()

+ 1 - 1
desktop/libs/hadoop/src/hadoop/fs/test_webhdfs.py

@@ -46,7 +46,7 @@ class WebhdfsTests(unittest.TestCase):
     try:
     try:
       self.cluster.fs.purge_trash()
       self.cluster.fs.purge_trash()
     except:
     except:
-      LOG.error('Could not clean up trash.')
+      LOG.exception('Could not clean up trash.')
 
 
   def test_webhdfs(self):
   def test_webhdfs(self):
     """
     """

+ 4 - 2
desktop/libs/indexer/src/indexer/conf.py

@@ -15,6 +15,7 @@
 # See the License for the specific language governing permissions and
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
+import logging
 import os
 import os
 from urlparse import urlparse
 from urlparse import urlparse
 
 
@@ -22,6 +23,7 @@ from django.utils.translation import ugettext_lazy as _t
 
 
 from desktop.lib.conf import Config
 from desktop.lib.conf import Config
 
 
+LOG = logging.getLogger(__name__)
 
 
 def solrctl():
 def solrctl():
   """
   """
@@ -46,14 +48,14 @@ def zkensemble():
     if clusters['default'].HOST_PORTS.get() != 'localhost:2181':
     if clusters['default'].HOST_PORTS.get() != 'localhost:2181':
       return '%s/solr' % clusters['default'].HOST_PORTS.get()
       return '%s/solr' % clusters['default'].HOST_PORTS.get()
   except:
   except:
-    pass
+    LOG.exception('failed to get zookeeper ensmble')
 
 
   try:
   try:
     from search.conf import SOLR_URL
     from search.conf import SOLR_URL
     parsed = urlparse(SOLR_URL.get())
     parsed = urlparse(SOLR_URL.get())
     return "%s:2181/solr" % (parsed.hostname or 'localhost')
     return "%s:2181/solr" % (parsed.hostname or 'localhost')
   except:
   except:
-    pass
+    LOG.exception('failed to get solr url')
 
 
 
 
 
 

+ 3 - 0
desktop/libs/indexer/src/indexer/utils.py

@@ -132,6 +132,7 @@ def get_field_types(field_list, iterations=3):
     try:
     try:
       parse(value)
       parse(value)
     except:
     except:
+      LOG.exception('failed to parse value %s' % value)
       raise ValueError()
       raise ValueError()
 
 
   def test_int(value):
   def test_int(value):
@@ -309,10 +310,12 @@ def field_values_from_log(fh, fields=[ {'name': 'message', 'type': 'text_general
     try:
     try:
       timestamp_key = next(iter(filter(lambda field: field['type'] in DATE_FIELD_TYPES, fields)))['name']
       timestamp_key = next(iter(filter(lambda field: field['type'] in DATE_FIELD_TYPES, fields)))['name']
     except:
     except:
+      LOG.exception('failed to get timestamp key')
       timestamp_key = None
       timestamp_key = None
     try:
     try:
       message_key = next(iter(filter(lambda field: field['type'] in TEXT_FIELD_TYPES, fields)))['name']
       message_key = next(iter(filter(lambda field: field['type'] in TEXT_FIELD_TYPES, fields)))['name']
     except:
     except:
+      LOG.exception('failed to get message key')
       message_key = None
       message_key = None
 
 
   def value_generator(buf):
   def value_generator(buf):

+ 4 - 1
desktop/libs/liboozie/src/liboozie/conf.py

@@ -15,12 +15,15 @@
 # See the License for the specific language governing permissions and
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
+import logging
 import sys
 import sys
 
 
 from django.utils.translation import ugettext as _, ugettext_lazy as _t
 from django.utils.translation import ugettext as _, ugettext_lazy as _t
 
 
 from desktop.lib.conf import Config, coerce_bool, validate_path
 from desktop.lib.conf import Config, coerce_bool, validate_path
 
 
+LOG = logging.getLogger(__name__)
+
 
 
 OOZIE_URL = Config(
 OOZIE_URL = Config(
   key='oozie_url',
   key='oozie_url',
@@ -56,7 +59,7 @@ def get_oozie_status(user):
     if not 'test' in sys.argv: # Avoid tests hanging
     if not 'test' in sys.argv: # Avoid tests hanging
       status = str(get_oozie(user).get_oozie_status())
       status = str(get_oozie(user).get_oozie_status())
   except:
   except:
-    pass
+    LOG.exception('failed to get oozie status')
 
 
   return status
   return status
 
 

+ 1 - 1
desktop/libs/liboozie/src/liboozie/submittion2_tests.py

@@ -139,7 +139,7 @@ def test_copy_files():
     try:
     try:
       cluster.fs.rmtree(prefix)
       cluster.fs.rmtree(prefix)
     except:
     except:
-      pass
+      LOG.exception('failed to remove %s' % prefix)
 
 
 
 
 class MockFs():
 class MockFs():

+ 1 - 1
desktop/libs/liboozie/src/liboozie/submittion_tests.py

@@ -119,7 +119,7 @@ def test_copy_files():
     try:
     try:
       cluster.fs.rmtree(prefix)
       cluster.fs.rmtree(prefix)
     except:
     except:
-      pass
+      LOG.exception('failed to remove %s' % prefix)
 
 
 
 
 class MockFs():
 class MockFs():

+ 1 - 1
desktop/libs/liboozie/src/liboozie/utils.py

@@ -21,7 +21,7 @@ Misc helper functions
 
 
 try:
 try:
   from cStringIO import StringIO
   from cStringIO import StringIO
-except:
+except ImportError:
   from StringIO import StringIO
   from StringIO import StringIO
 
 
 import logging
 import logging