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

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