From 485d2ab05077b3a67cf058f19ef9530d5503f412 Mon Sep 17 00:00:00 2001 From: Petr Sklenar Date: Jun 05 2017 08:11:12 +0000 Subject: [PATCH 1/2] tunning Makefile check-exceptions --- diff --git a/examples/testing-module/Makefile b/examples/testing-module/Makefile index 2310184..f846cea 100644 --- a/examples/testing-module/Makefile +++ b/examples/testing-module/Makefile @@ -41,7 +41,7 @@ check-run-them-fedmsg-testmodule: @true check-exceptions: - MODULEMDURL=XXX MODULE=nspawn $(CMD) --show-job-log simpleTest.py | grep 'raise ConfigExc' &>/dev/null + MODULEMDURL=XXX MODULE=nspawn $(CMD) --show-job-log simpleTest.py | grep 'raise ConfigExc' >/dev/null @true From c9139d3b81a10a3448cdb7ad126ea20566825ad6 Mon Sep 17 00:00:00 2001 From: Petr Sklenar Date: Jun 05 2017 11:14:52 +0000 Subject: [PATCH 2/2] it writes line numbers with errors --- diff --git a/moduleframework/common.py b/moduleframework/common.py index b69e42e..c242999 100644 --- a/moduleframework/common.py +++ b/moduleframework/common.py @@ -31,11 +31,19 @@ import sys import netifaces import socket import os - +import linecache class ModuleFrameworkException(Exception): def __init__(self, *args,**kwargs): super(ModuleFrameworkException, self).__init__('EXCEPTION MTF: ', *args,**kwargs) + exc_type, exc_obj, tb = sys.exc_info() + if tb is not None: + f = tb.tb_frame + lineno = tb.tb_lineno + filename = f.f_code.co_filename + linecache.checkcache(filename) + line = linecache.getline(filename, lineno, f.f_globals) + print "-----------\n| EXCEPTION IN: {} \n| LINE: {}, {} \n| ERROR: {}\n-----------".format(filename, lineno, line.strip(), exc_obj) class NspawnExc(ModuleFrameworkException): def __init__(self,*args,**kwargs): diff --git a/moduleframework/module_framework.py b/moduleframework/module_framework.py index b83f70f..0294c09 100644 --- a/moduleframework/module_framework.py +++ b/moduleframework/module_framework.py @@ -190,8 +190,7 @@ class CommonFunctions(object): link = self.modulemdConf return link except IOError as e: - exc_type, exc_obj, exc_tb = sys.exc_info() - raise ConfigExc("Cannot load file, {0}, line number: {1}".format(e, exc_tb.tb_lineno)) + raise ConfigExc("Cannot load file") def getIPaddr(self):