Decorator to convert throws errors to Voluptuous format.
12207
def _convert_errors(func):
    
    cast_Invalid = lambda e: Invalid(
        u"{message}, expected {expected}".format(
            message=e.message,
            expected=e.expected)
        if e.expected != u'-none-' else e.message,
        e.path,
        six.text_type(e))

    @wraps(func)
    def wrapper(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except good.SchemaError as e:
            raise SchemaError(six.text_type(e))
        except good.MultipleInvalid as ee:
            raise MultipleInvalid([cast_Invalid(e) for e in ee])
        except good.Invalid as e:
            # Since voluptuous throws MultipleInvalid almost always -- we follow the same pattern...
            raise MultipleInvalid([cast_Invalid(e)])
    return wrapper
339035
def convert(self, value):
        """"""
        try:
            return convert_to_format(value, self._format)
        except (ValueError, TypeError):
            return value
1294097
def format_error(self, error, args=None):
        
        if type(args) is dict:
            return error.format(**args)
        if type(args) is list or type(args) is tuple:
            return error.format(*args)

        return error
1207669
def numpy_invalid_op_as_exception(func):
    
    def func_wrapper(*args, **kwargs):
        np.seterr(invalid='raise')
        result = func(*args, **kwargs)
        np.seterr(invalid='warn')
        return result
    return func_wrapper
337674
def clean_fail(func):
    '''
    
    '''
    def func_wrapper(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except botocore.exceptions.ClientError as e:
            print(str(e), file=sys.stderr)
            sys.exit(1)
    return func_wrapper
1023274
function serializeError(err) {
  var o = {};

  Object.getOwnPropertyNames(err).forEach(function (k) {
    o[k] = err[k];
  });

  return _.omit(o, ['stack', 'type', 'arguments']);
}
219504
def validate_take_with_convert(convert, args, kwargs):
    

    if isinstance(convert, ndarray) or convert is None:
        args = (convert,) + args
        convert = True

    validate_take(args, kwargs, max_fname_arg_count=3, method='both')
    return convert
656610
def log_template_errors(logger, log_level=logging.ERROR):
    
    if not (isinstance(log_level, int) and
            log_level in logging._levelNames):
        raise ValueError('Invalid log level %s' % log_level)

    decorators = [
        _log_template_string_if_invalid(logger, log_level),
        _log_unicode_errors(logger, log_level),
        _always_strict_resolve,
    ]
    if django.VERSION < (1, 8):
        decorators.append(_patch_invalid_var_format_string)

    @decorator
    def function(f, *args, **kwargs):
        return reduce(__apply, decorators, f)(*args, **kwargs)

    return function
1274884
function formatErrors(errors, formatters, errorType) {
  const format = (formatter) => formatter(errors, errorType) || [];
  const flatten = (accum, curr) => accum.concat(curr);

  return formatters.map(format).reduce(flatten, [])
}
661116
def _conversion_function(pt_wrapper, dtype=None, name=None, as_ref=False):
  """"""
  # Ignore as_ref to not create backward compatibility issues.
  _ = name, as_ref
  t = pt_wrapper.tensor
  if dtype and not dtype.is_compatible_with(t.dtype):
    raise ValueError(
        'Tensor conversion requested dtype %s for Tensor with dtype %s: %r' %
        (dtype, t.dtype, t))
  return t
371692
def not26(func):
    """"""

    @wraps(func)
    def errfunc(*args, **kwargs):
        raise NotImplementedError

    if hexversion < 0x02070000:
        return errfunc
    else:
        return func
934430
def format(self, typedval):
        ''
        if typedval is None:
            return None

        if isinstance(typedval, (list, tuple)):
            return '[%s]' % len(typedval)
        if isinstance(typedval, dict):
            return '{%s}' % len(typedval)
        if isinstance(typedval, bytes):
            typedval = typedval.decode(options.encoding, options.encoding_errors)

        return getType(self.type).formatter(self.fmtstr, typedval)
1033683
def prepare_raise(func):
    

    @functools.wraps(func)
    def decorator(type_, value=None, traceback=None):
        if value is not None and isinstance(type_, Exception):
            raise TypeError("instance exception may not have a separate value")

        if value is None:
            if isinstance(type_, Exception):
                error = type_
            else:
                error = type_()
        else:
            error = type_(value)
        func(error, value, traceback)

    return decorator
561031
def format_error(e):
    

    if isinstance(e, PyMacaronException):
        return e.to_model()

    if isinstance(e, PyMacaronCoreException) and e.__class__.__name__ == 'ValidationError':
        return ValidationError(str(e)).to_model()

    # Turn this exception into a PyMacaron Error model
    return UnhandledServerError(str(e)).to_model()
370367
def handle_errors(f):
    
    import traceback
    from plone.jsonapi.core.helpers import error

    def decorator(*args, **kwargs):
        try:
            return f(*args, **kwargs)
        except Exception:
            var = traceback.format_exc()
            return error(var)

    return decorator
229752
def _coerce_method(converter):
    

    def wrapper(self):
        if len(self) == 1:
            return converter(self.iloc[0])
        raise TypeError("cannot convert the series to "
                        "{0}".format(str(converter)))

    wrapper.__name__ = "__{name}__".format(name=converter.__name__)
    return wrapper
611764
def format_error(module, error):
    """"""
    logging.error(module)
    # Beautify JSON error
    print error.message
    print json.dumps(error.error, sort_keys=True, indent=4, separators=(',', ': '))
    exit(1)