Make errors serializeable
498421
function error(err) {
    if (!(err instanceof Error)) return err
    return {
        code: err.code,
        message: err.message,
        details: err.detail,
        stack: err.stack || ''
    }
}
880603
def serialize(self, tag):
        """"""
        handler = getattr(self, f'serialize_{tag.serializer}', None)
        if handler is None:
            raise TypeError(f'Can\'t serialize {type(tag)!r} instance')
        return handler(tag)
1166023
private Entity<String> serialize(Object obj, String contentType) throws ClientErrorException {
        if (contentType.startsWith("application/json")) {
            try {
                return Entity.json(jsonMarshaller.serialize(obj));
            } catch (JsonMarshallingException e) {
                String msg = "Failed marshalling object to JSON data for sending to server: "+e.getMessage();
//                throw new ClientErrorException(Response.Status.BAD_REQUEST, e);
                throw new BadRequestServiceException(
                        new RestFaultInfo("BadRequest", Blame.CLIENT,
                                msg, ""+ ErrorCodes.Client.MARSHALLING_FAILED.getCode(),
                                null,
                                Retry.no(), Retry.no(),
                                Response.Status.BAD_REQUEST.getStatusCode(),
                                Response.Status.BAD_REQUEST.getReasonPhrase()
                        ), e
                );
            }
        } else {
            String msg = "Content type \"" + contentType + "\" is not supported.";
//            throw new NotSupportedException(msg);
            throw new BadRequestServiceException(
                    new RestFaultInfo("BadRequest", Blame.CLIENT,
                            msg, ""+ ErrorCodes.Client.UNSUPPORTED_TECHNOLOGY.getCode(),
                            null,
                            Retry.no(), Retry.no(),
                            Response.Status.BAD_REQUEST.getStatusCode(),
                            Response.Status.BAD_REQUEST.getReasonPhrase()
                    )
            );
        }
    }
529330
def _generate_serializable_funcs(self, data_type_name):
        """"""
        with self.block_func(
                func='serialize',
                args=fmt_func_args_declaration([('instance', 'id')]),
                return_type='nullable NSDictionary<NSString *, id>  *',
                class_func=True):
            func_call = fmt_func_call(
                caller=fmt_serial_class(data_type_name),
                callee='serialize',
                args=fmt_func_args([('instance', 'instance')]))
            self.emit('return {};'.format(func_call))
        self.emit()

        with self.block_func(
                func='deserialize',
                args=fmt_func_args_declaration([('dict', 'NSDictionary<NSString *, id>  *')]),
                return_type='id',
                class_func=True):
            self.emit('return {};'.format(
                fmt_func_call(
                    caller=fmt_serial_class(data_type_name),
                    callee='deserialize',
                    args=fmt_func_args([('dict', 'dict')]))))
        self.emit()
394698
def stringify(self, obj, beautify=False, raise_exception=False):
        """"""

        return self.helper.string.serialization.json.stringify(
            obj=obj,
            beautify=beautify,
            raise_exception=raise_exception)
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, [])
}
757359
@SuppressWarnings("unchecked")
    protected JsonObject paramError(Map<String, Object> errors) {
        JsonObject json = JsonObject.create();
        json.setStatus(GlobalResponseStatusMsg.SYSTEM_ERROR.getMessage().getCode());
        Map<String, Object> error = new HashMap<String, Object>();
        error.put(WebResponseConstant.MESSAGE_FIELD, errors);
        json.setStatusInfo(error);
        return json;
    }
895508
def strip_errors(obj):
    
    rtn_obj = copy.deepcopy(obj)
    try:
        del rtn_obj["__error_keys__"]
    except KeyError:
        pass
    for key in obj.get('__error_keys__', []):
        rtn_obj[key] = rtn_obj[key]['value']
    return rtn_obj
618417
function(errors, options) {
      options = options || {};

      var ret = []
        , prettify = options.prettify || v.prettify;
      errors.forEach(function(errorInfo) {
        var error = v.result(errorInfo.error,
            errorInfo.value,
            errorInfo.attribute,
            errorInfo.options,
            errorInfo.attributes,
            errorInfo.globalOptions);

        if (!v.isString(error)) {
          ret.push(errorInfo);
          return;
        }

        if (error[0] === '^') {
          error = error.slice(1);
        } else if (options.fullMessages !== false) {
          error = v.capitalize(prettify(errorInfo.attribute)) + " " + error;
        }
        error = error.replace(/\\\^/g, "^");
        error = v.format(error, {
          value: v.stringifyValue(errorInfo.value, options)
        });
        ret.push(v.extend({}, errorInfo, {error: error}));
      });
      return ret;
    }
206591
function addError(data, error) {
	if (!data.error) {
		data.error = [];
	}
	error.lineNumber = data.lineNumber;
	data.error.push(error);
}
429515
def make_serializable(data):
    """"""
    if is_serializable(data):
        return data

    # if numpy array convert to list
    try:
        return data.tolist()
    except AttributeError:
        pass
    except Exception as e:
        logger.debug('{} exception ({}): {}'.format(type(e).__name__, e, data))

    # try serializing each child element
    if isinstance(data, dict):
        return {key: make_serializable(value) for key, value in data.items()}
    try:
        return [make_serializable(element) for element in data]
    except TypeError:  # not iterable
        pass
    except Exception:
        logger.debug('Could not serialize {}; converting to string'.format(data))

    # last resort: convert to string
    return str(data)
691742
def errors(self,
               errors: List[str],
               code: Union[int, Tuple[int, str, str]] = HTTPStatus.BAD_REQUEST,
               key: str = 'errors',
               headers: Optional[Dict[str, str]] = None,
               ):
        
        return jsonify({key: errors}), code, headers or {}
1194178
public void addError(Throwable error) {
        if (error == null) {
            throw new NullPointerException("Error cannot be null");
        }
        if (error instanceof AssumptionViolatedException) {
            AssertionError e = new AssertionError(error.getMessage());
            e.initCause(error);
            errors.add(e);
        } else {
            errors.add(error);
        }
    }
1084416
def json_error(code, message):
    """"""
    # Message can be an unserializable object.
    message = repr(message)
    return jsonify(dict(request=request.path, message=message)), code
490014
function generateReturnableError(error) {
    if (_.isError(error)) {
        return {
            body: {error: error.message},
            options: {code: httpCodes.INTERNAL_SERVER_ERROR}
        };
    }
    if (_.isString(error)) {
        return {
            body: {error},
            options: {code: httpCodes.INTERNAL_SERVER_ERROR}
        };
    }
    if (_.isObject(error) && !_.isFunction(error)) {
        if (_.isArray(error)) {
            return {
                body: {error},
                options: {code: httpCodes.INTERNAL_SERVER_ERROR}
            };
        }
        let code = error.code || httpCodes.INTERNAL_SERVER_ERROR;
        delete error.code;
        return {
            body: error,
            options: {code}
        };
    }
    if (_.isFunction(error)) {
        return {
            body: {error: 'Incorrect error type "function"'},
            options: {code: httpCodes.INTERNAL_SERVER_ERROR}
        };
    }
    return {
        body: {error: 'Unexpected error format'},
        options: {code: httpCodes.INTERNAL_SERVER_ERROR}
    };
}
1059032
function formatError(e) {
  if (!e.err) return e.message;
  if (e.err.message) return e.err.message;
  return JSON.stringify(e.err);
}
643954
def serialize(self, data):
        
        if data is None:
            return None
        elif isinstance(data, dict):
            return serializer.Serializer().serialize(data)
        else:
            raise Exception(_("Unable to serialize object of type = '%s'") %
                            type(data))