Uniqueness validator
@param {mixed} attr
@param {mixed} conf
@param {mixed} err
@param {Function} done
338371
function validateUniqueness(attr, conf, err, done) {
    var cond = {where: {}};
    cond.where[attr] = this[attr];
    this.constructor.all(cond, function (error, found) {
        if (found.length > 1) {
            err();
        } else if (found.length === 1 && (!this.id || !found[0].id || found[0].id.toString() !== this.id.toString())) {
            err();
        }
        done();
    }.bind(this));
}
1217893
function(err){
                var error = null,
                    keys = null,
                    errMsg = '';

                if(err.name == 'ValidationError'){
                    keys = _.keys(err.errors);

                    if(err.errors[keys[0]].path === 'salt'){
                        //Support for virtual fields.
                        errMsg = err.errors[keys[0]].message;
                    }
                    else if(err.errors[keys[0]].type === 'required'){
                        errMsg = '"' + err.errors[keys[0]].path + '" is a required field.';
                    }
                    else {
                        errMsg = err.errors[keys[0]].message;
                    }

                    error = createError(400, errMsg);
                }
                else if (err.name == 'MongoError' && (err.code == '11001' || err.code == '11000')) {
                    error = createError(400, 'Duplicate key already exists.');
                }
                else {
                    error = createError(err);
                }

                return error;
            }
1175690
function validateURL(model, done) {
  var url = model.driver_url;
  parseURL(url, {}, function(err, result) {
    // URL parsing errors are just generic `Error` instances
    // so overwrite name so mongodb-js-server will know
    // the message is safe to display.
    if (err) {
      err.name = 'MongoError';
    }
    done(err, result);
  });
}
1324948
function creds(done) {
  var configPath = './config.json';
  try { CONFIG = JSON.parse(fs.readFileSync(configPath)); }
  catch(e) {
    beep();
    console.log('[AWS]'.bold.red + ' Sorry, there was an issue locating your config.json. Please see README.md');
    process.exit();
  }
  done();
}
740323
def validate_attr(self, append):
        """"""
        if append:
            existing_fields = getattr(self.attrs, self.kind_attr, None)
            if (existing_fields is not None and
                    existing_fields != list(self.values)):
                raise ValueError("appended items do not match existing items"
                                 " in table!")

            existing_dtype = getattr(self.attrs, self.dtype_attr, None)
            if (existing_dtype is not None and
                    existing_dtype != self.dtype):
                raise ValueError("appended items dtype do not match existing "
                                 "items dtype in table!")
1099471
private String checkConflict(Element elem, String oldAttrValue, String attr)
			throws JspCoreException {

		String result = oldAttrValue;
		String attrValue = null; 
		if (elem.getAttributeNode(attr) != null ) {
			attrValue = elem.getAttributeNode(attr).getValue();
		}
		if (attrValue != null) {
			if (oldAttrValue != null && !oldAttrValue.equals(attrValue)) {
	            throw new JspTranslationException(
	                    elem,
	                    "jsp.error.tag.conflict.attr",
	                    new Object[] { attr, oldAttrValue, attrValue });
			}
			result = attrValue;
		}
		return result;
	}
198797
function validateNumericality(attr, conf, err) {
    if (nullCheck.call(this, attr, conf, err)) return;

    if (typeof this[attr] !== 'number') {
        return err('number');
    }
    if (conf.int && this[attr] !== Math.round(this[attr])) {
        return err('int');
    }
}
165946
function(model, attrs) {
      attrs = attrs || _.keys(_.result(model, 'validation') || {});
      return _.reduce(attrs, function(memo, key) {
        memo[key] = void 0;
        return memo;
      }, {});
    }
42709
function normalizeErr(err, config) {
  const { name, message, actual, expected, stack, showDiff } = err;
  let errMessage;
  let errDiff;

  /**
   * Check that a / b have the same type.
   */
  function sameType(a, b) {
    const objToString = Object.prototype.toString;
    return objToString.call(a) === objToString.call(b);
  }

  // Format actual/expected for creating diff
  if (showDiff !== false && sameType(actual, expected) && expected !== undefined) {
    /* istanbul ignore if */
    if (!(_.isString(actual) && _.isString(expected))) {
      err.actual = mochaUtils.stringify(actual);
      err.expected = mochaUtils.stringify(expected);
    }
    errDiff = config.useInlineDiffs ? createInlineDiff(err) : createUnifiedDiff(err);
  }

  // Assertion libraries do not output consitent error objects so in order to
  // get a consistent message object we need to create it ourselves
  if (name && message) {
    errMessage = `${name}: ${stripAnsi(message)}`;
  } else if (stack) {
    errMessage = stack.replace(/\n.*/g, '');
  }

  return {
    message: errMessage,
    estack: stack && stripAnsi(stack),
    diff: errDiff
  };
}
1210460
function createJsonError(attribute) {
    const name = !attribute
      ? node.type
      : `${node.type} with ${attribute}=${JSON.stringify(node[attribute])}`;
    return createError(`${name} is not allowed in JSON.`, {
      start: {
        line: node.loc.start.line,
        column: node.loc.start.column + 1
      }
    });
  }
738777
def add_unique(self, attr, item):
        
        return self.set(attr, operation.AddUnique([item]))
446824
function(attrs, options) {
      if (options.silent || !this.validate) {
        return true;
      }
      attrs = _.extend({}, this.attributes, attrs);
      var error = this.validate(attrs, options);
      if (!error) {
        return true;
      }
      if (options && options.error) {
        options.error(this, error, options);
      } else {
        this.trigger('error', this, error, options);
      }
      return false;
    }
338919
function validate(key, values) {
  var typedef, value;

  if(!~Keys.indexOf(key)) {
    throw new Error('unknown configuration key: ' + key);
  }

  // retrieve the type definition
  typedef = Types[key];

  // validate on the typedef
  try {
    value = typedef.validate(key, values);
  }catch(e) {
    // got a more specific error message to throw
    if(typeof validator[key] === 'object'
      && validator[key].error) {
      throw validator[key].error;
    }
    throw e;
  }

  return value;
}
1031165
private static void validateMappedBy(Attribute attr, Attribute mappedByAttr) {
    if (mappedByAttr != null) {
      if (!isSingleReferenceType(mappedByAttr)) {
        throw new MolgenisDataException(
            format(
                "Invalid mappedBy attribute [%s] data type [%s].",
                mappedByAttr.getName(), mappedByAttr.getDataType()));
      }

      Attribute refAttr = attr.getRefEntity().getAttribute(mappedByAttr.getName());
      if (refAttr == null) {
        throw new MolgenisDataException(
            format(
                "mappedBy attribute [%s] is not part of entity [%s].",
                mappedByAttr.getName(), attr.getRefEntity().getId()));
      }
    }
  }
758422
function normalizeValidator(validator) {
	        if (validator.validate !== undefined) {
	            return function (c) { return validator.validate(c); };
	        }
	        else {
	            return validator;
	        }
	    }
1217540
function unique( field ) {
   const seen = {};
   const id = field ? value => value[ field ] : value => value;

   return value => {
      const key = id( value );
      if( seen[ key ] ) {
         return false;
      }
      seen[ key ] = true;
      return true;
   };
}
1348586
def random_uniq_attr(field, **options, &block)
      set_method = :"set_#{field}"
      generate_method = :"generate_#{field}"
      max_attempts = options.fetch(:max_attempts) { MAX_ATTEMPTS }

      after_create set_method, unless: :"#{field}?"

      # def self.generate_key
      define_singleton_method generate_method, &(block || DEFAULT_GENERATOR)

      # def set_key
      define_method(set_method) do
        attempt = 0
        begin
          raise 'Available only for persisted record' unless persisted?
          transaction(requires_new: true) do
            new_value = self.class.send(generate_method, self)
            update_column field, new_value # rubocop:disable Rails/SkipsModelValidations
          end
        rescue ActiveRecord::RecordNotUnique
          attempt += 1
          raise if attempt > max_attempts
          retry
        end
      end
    end