pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] srkukarni commented on a change in pull request #2847: Cleanup Logging for python functions
Date Thu, 25 Oct 2018 22:06:27 GMT
srkukarni commented on a change in pull request #2847: Cleanup Logging for python functions
URL: https://github.com/apache/pulsar/pull/2847#discussion_r228350675
 
 

 ##########
 File path: pulsar-functions/instance/src/main/python/util.py
 ##########
 @@ -36,38 +36,33 @@
 def import_class(from_path, full_class_name):
   from_path = str(from_path)
   full_class_name = str(full_class_name)
-  kclass = import_class_from_path(from_path, full_class_name)
-  if kclass is None:
+  try:
+    return import_class_from_path(from_path, full_class_name)
+  except Exception as e:
     our_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
     api_dir = os.path.join(our_dir, PULSAR_API_ROOT, PULSAR_FUNCTIONS_API_ROOT)
-    kclass = import_class_from_path(api_dir, full_class_name)
-  return kclass
+    try:
+      return import_class_from_path(api_dir, full_class_name)
+    except Exception as e:
+      Log.info("Failed to import class %s from path %s" % (full_class_name, from_path))
+      Log.info(e, exc_info=True)
+      return None
 
 def import_class_from_path(from_path, full_class_name):
-  Log.info('Trying to import %s from path %s' % (full_class_name, from_path))
+  Log.debug('Trying to import %s from path %s' % (full_class_name, from_path))
   split = full_class_name.split('.')
   classname_path = '.'.join(split[:-1])
   class_name = full_class_name.split('.')[-1]
   if from_path not in sys.path:
-    Log.info("Add a new dependency to the path: %s" % from_path)
+    Log.debug("Add a new dependency to the path: %s" % from_path)
     sys.path.insert(0, from_path)
   if not classname_path:
-    try:
-      mod = importlib.import_module(class_name)
-      return mod
-    except Exception as e:
-      Log.info("Import failed class_name %s from path %s" % (class_name, from_path))
-      Log.info(e, exc_info=True)
-      return None
+    mod = importlib.import_module(class_name)
 
 Review comment:
   Sorry, I mistook the part of the code.
   So this function is only called from the functions above(import_class). This function was
prev returning None in exceptions and this pr makes it throw an exception which the caller
calls and logs about that exception

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message