OpenRefine/OpenRefine · error · ValidationError

throw new ValidationError(vErrors);

Error message

 throw new ValidationError(vErrors); 

What it means

ajv code-generation template (bundled ajv.js in the Wikibase extension) at the end of a generated custom-rule/keyword check: when the rule records an error and fail-fast is active in an async schema, the generated code executes `throw new ValidationError(vErrors)` — throwing the accumulated `Ajv.ValidationError` to the caller instead of returning false.

Solutions

  1. Handle the throw with try/catch and use `e.errors` for diagnostics.
  2. Enable `allErrors: true` on the Ajv instance to avoid the fail-fast throw.
  3. Verify the custom keyword's validate function; fix its inputs or its error reporting.
  4. Make the schema synchronous if the custom keyword is not truly async.

Example fix

// before
const result = await validate(item); // throws ValidationError from custom keyword

// after
const ajv = new Ajv({ allErrors: true }); // collect errors, return false instead of throw
const validate = await ajv.compileAsync(schema);
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-screen with a sync dry-run to catch custom-keyword violations early:
const dry = new Ajv({ allErrors: true });
dry.addKeyword('myKeyword', { validate: mySyncProxy });
if (!dry.validate(schemaWithoutAsync, data)) console.warn(dry.errors);

Type guard

function isAjvValidationError(e) { return e instanceof Error && Array.isArray(e.errors) && typeof e.message === 'string'; }

Try / catch

try {
  await validate(item);
} catch (e) {
  if (isAjvValidationError(e)) handleInvalidItem(item, e.errors);
  else throw e;
}

Prevention

When it happens

Trigger: A custom keyword or rule validation fails while running a compiled async validator; because `!it.compositeRule && $breakOnError`, the emitted code throws `new ValidationError(vErrors)` with all errors collected so far.

Common situations: Schemas using custom ajv keywords (format, user-defined rules) inside async validation; plugin/bundled contexts (like the Wikibase extension) where the throw surfaces as an unexpected exception from `validate()`.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of OpenRefine/OpenRefine@a946177e04 (2026-09-08). Data as JSON: /api/errors/47c0ff589a398c50. Report an issue: GitHub.

Appendix: source

Thrown at extensions/wikibase/module/scripts/ajv.js:2794

    }
    out += ' if (!' + ($valid) + ') {   var err =   '; /* istanbul ignore else */
    if (it.createErrors !== false) {
      out += ' { keyword: \'' + ('if') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { failingKeyword: ' + ($ifClause) + ' } ';
      if (it.opts.messages !== false) {
        out += ' , message: \'should match "\' + ' + ($ifClause) + ' + \'" schema\' ';
      }
      if (it.opts.verbose) {
        out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
      }
      out += ' } ';
    } else {
      out += ' {} ';
    }
    out += ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
    if (!it.compositeRule && $breakOnError) {
      /* istanbul ignore if */
      if (it.async) {
        out += ' throw new ValidationError(vErrors); ';
      } else {
        out += ' validate.errors = vErrors; return false; ';
      }
    }
    out += ' }   ';
    if ($breakOnError) {
      out += ' else { ';
    }
  } else {
    if ($breakOnError) {
      out += ' if (true) { ';
    }
  }
  return out;
}

},{}],27:[function(require,module,exports){
'use strict';

View on GitHub (pinned to a946177e04)