How to use the debrief.annotateFields function in debrief

To help you get started, we’ve selected a few debrief examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nvie / decoders / src / object.js View on Github external
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);
github nvie / decoders / src / mapping.js View on Github external
}
                } 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));
            }
        }
    );

debrief

Object serialization and annotation, for use in human-friendly error messages

MIT
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis