Skip to content

Commit

Permalink
fix(core): improve error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter John committed Nov 8, 2014
1 parent 9e3075a commit 2b1fed0
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/themis.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ var Utils = {
best_score = -1;
best_match = null;
}
score = error.relative_schema_path.split('/').length;
score = error.schema_path.split('/').length;
if (best_match == null || best_score > score) {
best_score = score;
best_match = [];
Expand Down Expand Up @@ -377,6 +377,7 @@ var Utils = {
while (index--) {
var report = reports[index];
var score = report.passed;
delete report.passed;
if (best_reports == null || score > best_report_score) {
best_report_score = score;
best_reports = [];
Expand Down Expand Up @@ -600,8 +601,8 @@ var buildError = function (error_code, schema, schema_path, relative_schema_path
"report.errors.push({",
"code: '"+ error_code +"',",
"path: path,",
"instance: data,",
"validator: '"+ validator +"'"
"instance: data, ",
"schema_path: '"+ schema_path + ((validator_value == null) ? '' : relative_schema_path) + "'"
];

if (options.errors.messages) {
Expand All @@ -616,9 +617,10 @@ var buildError = function (error_code, schema, schema_path, relative_schema_path
}
}

if (validator_value != null && options.errors.validator_value) {
if (options.errors.validator) {
code.push(
", validator_value: " + Utils.stringify(validator_value)
", validator_value: " + Utils.stringify(validator_value),
", validator: '"+ validator +"'"
);
}

Expand All @@ -630,15 +632,12 @@ var buildError = function (error_code, schema, schema_path, relative_schema_path

if (options.errors.schema) {
code.push(
", schema: _schema "
", schema: _schema ",
", relative_schema_path: '"+ relative_schema_path + "'",
", absolute_schema_path: '"+ schema_path + ((validator_value == null) ? '' : relative_schema_path) + "'"
);
}

code.push(
", relative_schema_path: '"+ relative_schema_path + "'",
", absolute_schema_path: '"+ schema_path + ((validator_value == null) ? '' : relative_schema_path) + "'"
);

if (build_context) {
code.push(
", context: context"
Expand Down Expand Up @@ -1844,8 +1843,8 @@ var buildValidator = function (schemas, options) {
var body, index, validator, schema, SCHEMA_ID, code;

Utils.defaults(options.errors, {
schema: true,
validator_value: true,
schema: false,
validator: false,
messages: true
});

Expand Down

0 comments on commit 2b1fed0

Please sign in to comment.