Skip to content

Commit

Permalink
[python-experimental] Add support for pep 3134, attach cause of excep…
Browse files Browse the repository at this point in the history
…tion (#6388)

* Mustache template should use invokerPackage tag to generate import

* Add exception cause

* using six module for exception chaining in Python 3.x
  • Loading branch information
sebastien-rosset authored May 22, 2020
1 parent 912604f commit 19e1423
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -725,14 +725,14 @@ def deserialize_primitive(data, klass, path_to_item):
# '7' -> 7.0 -> '7.0' != '7'
raise ValueError('This is not a float')
return converted_value
except (OverflowError, ValueError):
except (OverflowError, ValueError) as ex:
# parse can raise OverflowError
raise ApiValueError(
six.raise_from(ApiValueError(
"{0}Failed to parse {1} as {2}".format(
additional_message, repr(data), get_py3_class_name(klass)
),
path_to_item=path_to_item
)
), ex)


def get_discriminator_class(model_class,
Expand Down Expand Up @@ -1220,7 +1220,7 @@ def get_allof_instances(self, model_args, constant_args):
allof_instance = allof_class(**kwargs)
composed_instances.append(allof_instance)
except Exception as ex:
raise ApiValueError(
six.raise_from(ApiValueError(
"Invalid inputs given to generate an instance of '%s'. The "
"input data was invalid for the allOf schema '%s' in the composed "
"schema '%s'. Error=%s" % (
Expand All @@ -1229,7 +1229,7 @@ def get_allof_instances(self, model_args, constant_args):
self.__class__.__name__,
str(ex)
)
)
), ex)
return composed_instances


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -992,14 +992,14 @@ def deserialize_primitive(data, klass, path_to_item):
# '7' -> 7.0 -> '7.0' != '7'
raise ValueError('This is not a float')
return converted_value
except (OverflowError, ValueError):
except (OverflowError, ValueError) as ex:
# parse can raise OverflowError
raise ApiValueError(
six.raise_from(ApiValueError(
"{0}Failed to parse {1} as {2}".format(
additional_message, repr(data), get_py3_class_name(klass)
),
path_to_item=path_to_item
)
), ex)


def get_discriminator_class(model_class,
Expand Down Expand Up @@ -1487,7 +1487,7 @@ def get_allof_instances(self, model_args, constant_args):
allof_instance = allof_class(**kwargs)
composed_instances.append(allof_instance)
except Exception as ex:
raise ApiValueError(
six.raise_from(ApiValueError(
"Invalid inputs given to generate an instance of '%s'. The "
"input data was invalid for the allOf schema '%s' in the composed "
"schema '%s'. Error=%s" % (
Expand All @@ -1496,7 +1496,7 @@ def get_allof_instances(self, model_args, constant_args):
self.__class__.__name__,
str(ex)
)
)
), ex)
return composed_instances


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -992,14 +992,14 @@ def deserialize_primitive(data, klass, path_to_item):
# '7' -> 7.0 -> '7.0' != '7'
raise ValueError('This is not a float')
return converted_value
except (OverflowError, ValueError):
except (OverflowError, ValueError) as ex:
# parse can raise OverflowError
raise ApiValueError(
six.raise_from(ApiValueError(
"{0}Failed to parse {1} as {2}".format(
additional_message, repr(data), get_py3_class_name(klass)
),
path_to_item=path_to_item
)
), ex)


def get_discriminator_class(model_class,
Expand Down Expand Up @@ -1487,7 +1487,7 @@ def get_allof_instances(self, model_args, constant_args):
allof_instance = allof_class(**kwargs)
composed_instances.append(allof_instance)
except Exception as ex:
raise ApiValueError(
six.raise_from(ApiValueError(
"Invalid inputs given to generate an instance of '%s'. The "
"input data was invalid for the allOf schema '%s' in the composed "
"schema '%s'. Error=%s" % (
Expand All @@ -1496,7 +1496,7 @@ def get_allof_instances(self, model_args, constant_args):
self.__class__.__name__,
str(ex)
)
)
), ex)
return composed_instances


Expand Down

0 comments on commit 19e1423

Please sign in to comment.