From commits-return-16475-archive-asf-public=cust-asf.ponee.io@pulsar.apache.org Fri Oct 26 00:06:29 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id D6144180675 for ; Fri, 26 Oct 2018 00:06:28 +0200 (CEST) Received: (qmail 7561 invoked by uid 500); 25 Oct 2018 22:06:27 -0000 Mailing-List: contact commits-help@pulsar.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pulsar.apache.org Delivered-To: mailing list commits@pulsar.apache.org Received: (qmail 7552 invoked by uid 99); 25 Oct 2018 22:06:27 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Oct 2018 22:06:27 +0000 From: GitBox To: commits@pulsar.apache.org Subject: [GitHub] srkukarni commented on a change in pull request #2847: Cleanup Logging for python functions Message-ID: <154050518740.27896.170507236465263038.gitbox@gitbox.apache.org> Date: Thu, 25 Oct 2018 22:06:27 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit 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