diff --git a/murano/dsl/dsl_exception.py b/murano/dsl/dsl_exception.py index 36585327..c4ec4acf 100644 --- a/murano/dsl/dsl_exception.py +++ b/murano/dsl/dsl_exception.py @@ -20,7 +20,7 @@ import murano.dsl.yaql_functions as yaql_functions class MuranoPlException(Exception): def __init__(self, names, message, stacktrace, extra=None, cause=None): super(MuranoPlException, self).__init__( - '{0}: {1}'.format(names, message)) + '[{0}]: {1}'.format(', '.join(names), message)) if not isinstance(names, list): names = [names] self._names = names diff --git a/murano/tests/dsl/meta/ExceptionHandling.yaml b/murano/tests/dsl/meta/ExceptionHandling.yaml new file mode 100644 index 00000000..95799314 --- /dev/null +++ b/murano/tests/dsl/meta/ExceptionHandling.yaml @@ -0,0 +1,51 @@ +Name: ExceptionHandling + +Methods: + testThrow: + Arguments: + - enum: + Contract: $.int().notNull() + Body: + Try: + - trace('enter try') + - $.doThrow($enum) + - trace('exit try') + Catch: + - With: exceptionName + As: e + Do: + - trace($e.message) + - With: anotherExceptionName + As: e + Do: + - trace($e.message) + - trace(rethrow) + - Rethrow: + - As: e + Do: + - trace('catch all') + - trace($e.message) + Else: + - trace('else section') + Finally: + - trace('finally section') + + doThrow: + Arguments: + - enum: + Contract: $.int().notNull() + Body: + - Match: + 1: + - Throw: exceptionName + Message: exception message + 2: + - Throw: anotherExceptionName + Message: exception message 2 + 3: + - Throw: thirdExceptionName + Message: exception message 3 + 4: + - Return: + Value: $enum + diff --git a/murano/tests/dsl/test_exceptions.py b/murano/tests/dsl/test_exceptions.py new file mode 100644 index 00000000..8de91ebc --- /dev/null +++ b/murano/tests/dsl/test_exceptions.py @@ -0,0 +1,56 @@ +# Copyright (c) 2014 Mirantis, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from murano.dsl import dsl_exception +from murano.tests.dsl.foundation import object_model as om +from murano.tests.dsl.foundation import test_case + + +class TestExceptions(test_case.DslTestCase): + def setUp(self): + super(TestExceptions, self).setUp() + self._runner = self.new_runner(om.Object('ExceptionHandling')) + + def test_throw_catch(self): + self._runner.testThrow(1) + self.assertEqual( + ['enter try', u'exception message', 'finally section'], + self.traces) + + def test_rethrow(self): + e = self.assertRaises( + dsl_exception.MuranoPlException, + self._runner.testThrow, 2) + + self.assertEqual(['anotherExceptionName'], e.names) + self.assertEqual('exception message 2', e.message) + self.assertEqual('[anotherExceptionName]: exception message 2', str(e)) + + self.assertEqual( + ['enter try', 'exception message 2', + 'rethrow', 'finally section'], + self.traces) + + def test_catch_all_catch(self): + self._runner.testThrow(3) + self.assertEqual( + ['enter try', 'catch all', + 'exception message 3', 'finally section'], + self.traces) + + def test_no_throw(self): + self._runner.testThrow(4) + self.assertEqual( + ['enter try', 'exit try', 'else section', 'finally section'], + self.traces)