Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Object.keys(blob).forEach((key: string) => {
const value: T = blob[key];
const result = decoder(value);
try {
const okValue = result.unwrap();
if (errors.length === 0) {
tuples.push([key, okValue]);
}
} 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;
}
}
});
// NOTE: We're using .keys() here over .entries(), since .entries()
// will type the value part as "mixed"
for (const key of Object.keys(mapping)) {
const decoder = mapping[key];
const value = blob[key];
const result = decoder(value);
try {
record[key] = result.unwrap();
// If this succeeded, remove the key from the missing keys
// tracker
missing.delete(key);
} catch (ann) {
/* istanbul ignore next */
if (!isAnnotation(ann)) {
throw ann;
}
// Keep track of the annotation, but don't return just yet. We
// want to collect more error information.
if (value === undefined) {
// Explicitly add it to the missing set if the value is
// undefined. This covers explicit undefineds to be
// treated the same as implicit undefineds (aka missing
// keys).
missing.add(key);
} else {
fieldErrors[key] = ann;
}
}
}