Catch error in condition evaluation
And return a better message to users
This commit is contained in:
parent
3bb4b50ba0
commit
af33442ba2
2 changed files with 12 additions and 2 deletions
|
|
@ -33,6 +33,7 @@ from weboob.core.backendscfg import BackendsConfig
|
||||||
from weboob.tools.config.iconfig import ConfigError
|
from weboob.tools.config.iconfig import ConfigError
|
||||||
from weboob.tools.log import createColoredFormatter, getLogger
|
from weboob.tools.log import createColoredFormatter, getLogger
|
||||||
from weboob.tools.misc import to_unicode
|
from weboob.tools.misc import to_unicode
|
||||||
|
from .results import ResultsConditionError
|
||||||
|
|
||||||
__all__ = ['BaseApplication']
|
__all__ = ['BaseApplication']
|
||||||
|
|
||||||
|
|
@ -439,5 +440,8 @@ class BaseApplication(object):
|
||||||
except CallErrors as e:
|
except CallErrors as e:
|
||||||
app.bcall_errors_handler(e)
|
app.bcall_errors_handler(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
except ResultsConditionError as e:
|
||||||
|
print >>sys.stderr, '%s' % e
|
||||||
|
sys.exit(1)
|
||||||
finally:
|
finally:
|
||||||
app.deinit()
|
app.deinit()
|
||||||
|
|
|
||||||
|
|
@ -18,16 +18,19 @@
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import weboob.tools.date as date_utils
|
import weboob.tools.date as date_utils
|
||||||
|
from weboob.capabilities import UserError
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['ResultsCondition', 'ResultsConditionError']
|
__all__ = ['ResultsCondition', 'ResultsConditionError']
|
||||||
|
|
||||||
|
|
||||||
class IResultsCondition(object):
|
class IResultsCondition(object):
|
||||||
def is_valid(self, obj):
|
def is_valid(self, obj):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
class ResultsConditionError(Exception):
|
class ResultsConditionError(UserError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -79,7 +82,10 @@ class ResultsCondition(IResultsCondition):
|
||||||
break
|
break
|
||||||
if operator is None:
|
if operator is None:
|
||||||
raise ResultsConditionError(u'Could not find a valid operator in sub-expression "%s"' % _and)
|
raise ResultsConditionError(u'Could not find a valid operator in sub-expression "%s"' % _and)
|
||||||
l, r = _and.split(operator)
|
try:
|
||||||
|
l, r = _and.split(operator)
|
||||||
|
except ValueError:
|
||||||
|
raise ResultsConditionError(u'Syntax error in the condition expression, please check documentation')
|
||||||
and_list.append(Condition(l, operator, r))
|
and_list.append(Condition(l, operator, r))
|
||||||
or_list.append(and_list)
|
or_list.append(and_list)
|
||||||
self.condition = or_list
|
self.condition = or_list
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue