Fixe bad Python exception catch for C-launched scripts.

* In Hurricane::Viewer::Script::runFunction() & callFunction(), when the
    script returns NULL, do not immediately return but first check if an
    exception has been set. If so, print it *then* clear it.
      Due to not clearing the exception we where seeing one later with
    no relation to the true problem.
* In Oroshi/python/Rules.py, a bad test structure was discarting all the
    "no layer rule with physical length" in the loading process. It was
    blocked by the physical unit rule special cases.
This commit is contained in:
Jean-Paul Chaput 2019-12-19 01:18:11 +01:00
parent 41a49809d2
commit 26610ba80c
3 changed files with 24 additions and 14 deletions

View File

@ -202,6 +202,12 @@ namespace Analog {
) << endl; ) << endl;
return false; return false;
} }
if (not pCheckOk) {
cerr << Error( "%s\n A Python exception has occurred."
, _script->getFileName()
) << endl;
return false;
}
return true; return true;
} }

View File

@ -136,15 +136,16 @@ namespace Isobar {
_pyArgs = NULL; _pyArgs = NULL;
_pyKw = NULL; _pyKw = NULL;
if (_pyResult == NULL) {
cerr << "Something has gone slightly wrong" << endl;
}
if (PyErr_Occurred()) { if (PyErr_Occurred()) {
PyErr_Print(); PyErr_Print();
PyErr_Clear();
returnCode = false; returnCode = false;
} }
if (_pyResult == NULL) {
cerr << "Something has gone slightly wrong" << endl;
}
finalize(); finalize();
return returnCode; return returnCode;
@ -167,13 +168,16 @@ namespace Isobar {
_pyResult = PyObject_Call( _pyFunction, pyArgs, NULL ); _pyResult = PyObject_Call( _pyFunction, pyArgs, NULL );
if (PyErr_Occurred()) {
PyErr_Print();
PyErr_Clear();
}
if (_pyResult == NULL) { if (_pyResult == NULL) {
cerr << "Something has gone slightly wrong" << endl; cerr << "Something has gone slightly wrong" << endl;
return NULL; return NULL;
} }
if (PyErr_Occurred()) PyErr_Print();
return _pyResult; return _pyResult;
} }

View File

@ -87,7 +87,7 @@ class Rules ( object ):
, 'corrFactor90' , 'corrFactor90'
, 'corrFactor135' , 'corrFactor135'
, 'minRpolyhSquares' , 'minRpolyhSquares'
] ]
def __init__ ( self, dtr ): def __init__ ( self, dtr ):
trace( 100, '\tRules.__init__()\n' ) trace( 100, '\tRules.__init__()\n' )
@ -104,13 +104,13 @@ class Rules ( object ):
words = attribute.split( '_' ) words = attribute.split( '_' )
try: try:
if len(words) == 1: if len(words) == 1:
if words[0].endswith('Cap' ): value = self.dtr.getUnitRule( words[0] ).getValue() if words[0].endswith('Cap' ): value = self.dtr.getUnitRule( words[0] ).getValue()
if words[0].endswith('ContRes' ): value = self.dtr.getUnitRule( words[0] ).getValue() elif words[0].endswith('ContRes' ): value = self.dtr.getUnitRule( words[0] ).getValue()
if words[0].endswith('Res' ): value = self.dtr.getUnitRule( words[0] ).getValue() elif words[0].endswith('Res' ): value = self.dtr.getUnitRule( words[0] ).getValue()
if words[0].endswith('ctor90' ): value = self.dtr.getUnitRule( words[0] ).getValue() elif words[0].endswith('ctor90' ): value = self.dtr.getUnitRule( words[0] ).getValue()
if words[0].endswith('ctor135' ): value = self.dtr.getUnitRule( words[0] ).getValue() elif words[0].endswith('ctor135' ): value = self.dtr.getUnitRule( words[0] ).getValue()
if words[0].endswith('quares' ): value = self.dtr.getUnitRule( words[0] ).getValue() elif words[0].endswith('quares' ): value = self.dtr.getUnitRule( words[0] ).getValue()
elif len(words) < 4: if (value is None) and len(words) < 4:
value = self.dtr.getPhysicalRule( *tuple(words) ).getValue() value = self.dtr.getPhysicalRule( *tuple(words) ).getValue()
except Exception, e: except Exception, e:
print e print e