<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def from_validation_exception(cls, exception, **kwargs):
 """Create an error from validation exception."""

        errors = []

        def flatten(error, path=""):
            if isinstance(error, halogen.exceptions.ValidationError):
                if not path.endswith("/"):
                    path += "/"
                if error.attr is not None:
                    path += error.attr
                elif error.index is not None:
                    path += six.text_type(error.index)

                for e in error.errors:
                    flatten(e, path)
            else:
                message = error
                if isinstance(error, Exception):
                    try:
                        message = error.message
                    except AttributeError:
                        message = six.text_type(error)
                # TODO: i18n
                errors.append(Error(message=message, path=path))

        flatten(exception)
        message = kwargs.pop("message", "Validation error.")
        return cls(message=message, errors=sorted(errors, key=lambda error: error.path or ""), **kwargs)