Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fieldErrors[key] = ann;
}
}
}
// Deal with errors now. There are two classes of errors we want to
// report. First of all, we want to report any inline errors in this
// object. Lastly, any fields that are missing should be annotated on
// the outer object itself.
const fieldsWithErrors = Object.keys(fieldErrors);
if (fieldsWithErrors.length > 0 || missing.size > 0) {
let err;
if (fieldsWithErrors.length > 0) {
const errorlist = fieldsWithErrors.map(k => [k, fieldErrors[k]]);
err = annotateFields(blob, errorlist);
} else {
err = annotate(blob);
}
if (missing.size > 0) {
const errMsg = Array.from(missing)
.map(key => `"${key}"`)
.join(', ');
const pluralized = missing.size > 1 ? 'keys' : 'key';
err = annotate(err, `Missing ${pluralized}: ${errMsg}`);
}
return Err(err);
}
return Ok(record);
}
} catch (e) {
/* istanbul ignore else */
if (isAnnotation(e)) {
tuples.length = 0; // Clear the tuples array
errors.push([key, e]);
} else {
// Otherwise, simply rethrow it
/* istanbul ignore next */
throw e;
}
}
});
if (errors.length > 0) {
return Err(annotateFields(blob, errors));
} else {
return Ok(new Map(tuples));
}
}
);