[Groonga-commit] groonga/gcs [master] Raise InvalidType error for index fields with invalid options

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Nov 15 18:40:46 JST 2012


YUKI Hiroshi	2012-11-15 18:40:46 +0900 (Thu, 15 Nov 2012)

  New Revision: edd6cf579eef9842d73546d37e28881d3edf218a
  https://github.com/groonga/gcs/commit/edd6cf579eef9842d73546d37e28881d3edf218a

  Log:
    Raise InvalidType error for index fields with invalid options

  Modified files:
    lib/database/index-field.js
    lib/errors.js

  Modified: lib/database/index-field.js (+11 -0)
===================================================================
--- lib/database/index-field.js    2012-11-15 18:30:54 +0900 (63fe18f)
+++ lib/database/index-field.js    2012-11-15 18:40:46 +0900 (b0bdc00)
@@ -1,5 +1,6 @@
 var nroonga = require('../wrapped-nroonga');
 var ValidationError = require('../errors').ValidationError;
+var FieldTypeValidationError = require('../errors').FieldTypeValidationError;
 
 var MINIMUM_NAME_LENGTH =
       exports.MINIMUM_NAME_LENGTH =
@@ -231,6 +232,7 @@ IndexField.prototype = {
       throw new Error('facet option cannot be configured for the type ' + this.type + '.');
 
     this._facetEnabled = booleanValue;
+    this.validateOptions();
     return value;
   },
   setFacetEnabled: function(value) {
@@ -257,6 +259,7 @@ IndexField.prototype = {
       throw new Error('returnable option cannot be configured for the type ' + this.type + '.');
 
     this._resultEnabled = !!value;
+    this.validateOptions();
     return value;
   },
   setResultEnabled: function(value) {
@@ -284,6 +287,7 @@ IndexField.prototype = {
       throw new Error('searchable option cannot be configured for the type ' + this.type + '.');
 
     this._searchEnabled = booleanValue;
+    this.validateOptions();
     return value;
   },
   setSearchEnabled: function(value) {
@@ -467,6 +471,13 @@ IndexField.prototype = {
     this.createSync(true);
     this.domain.loadSync(values);
     return this;
+  },
+
+  validateOptions: function() {
+    if (this.facetEnabled && this.resultEnabled)
+      throw new FieldTypeValidationError(
+              'Error defining field: ' + this.name + '. ' +
+              'An IndexField may not be both FacetEnabled and ResultEnabled');
   }
 };
 

  Modified: lib/errors.js (+15 -0)
===================================================================
--- lib/errors.js    2012-11-15 18:30:54 +0900 (c1846c2)
+++ lib/errors.js    2012-11-15 18:40:46 +0900 (41b8798)
@@ -13,6 +13,21 @@ ValidationError.isValidationError = function(error) {
 exports.ValidationError = ValidationError;
 
 
+function FieldTypeValidationError(message) {
+  var error = new Error(message);
+  error.isValidationError = true;
+  error.isSenderError = true;
+  error.code = 'InvalidType';
+  return error;
+}
+
+FieldTypeValidationError.isFieldTypeValidationError = function(error) {
+  return !!error.isFieldTypeValidationError;
+};
+
+exports.FieldTypeValidationError = FieldTypeValidationError;
+
+
 function NotFoundError(message) {
   var error = new Error(message);
   error.isNotFoundError = true;
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index