"use strict";
/**
 * Uniform error handling for Liza: error context
 *
 *  Copyright (C) 2010-2019 R-T Specialty, LLC.
 *
 *  This file is part of the Liza Data Collection Framework.
 *
 *  liza is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * This context system is intended to play nicely with how Error objects are
 * typically used in JavaScript.  As such, rather than creating new error
 * prototypes / subclasses, these rely on structural typing to augment
 * existing `Error` objects.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.context = exports.hasContext = void 0;
/**
 * Type predicate for `ContextError`
 *
 * Note that this is a predicate for a generic `ContextError`, type, which
 * is equivalent to `ContextError<ErrorContext>`.  Other contexts must
 * define their own predicates.
 *
 * @param e error object
 *
 * @return whether `e` is of type `ContextError`
 */
exports.hasContext = function (e) {
    return e.context !== undefined;
};
/**
 * Adds context to an error
 *
 * This is intended to be used as if it were a constructor, where the first
 * argument is a new `Error` instance.
 *
 * @param enew    error object to add context to
 * @param context key/value context information
 */
function context(enew, context) {
    enew.context = context;
    return enew;
}
exports.context = context;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ29udGV4dEVycm9yLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiQ29udGV4dEVycm9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBd0JHOzs7QUFtQ0g7Ozs7Ozs7Ozs7R0FVRztBQUNVLFFBQUEsVUFBVSxHQUFHLFVBQUMsQ0FBUTtJQUNqQyxPQUFlLENBQUUsQ0FBQyxPQUFPLEtBQUssU0FBUztBQUF2QyxDQUF1QyxDQUFDO0FBRTFDOzs7Ozs7OztHQVFHO0FBQ0gsU0FBZ0IsT0FBTyxDQUNyQixJQUFXLEVBQ1gsT0FBVTtJQUVxQixJQUFLLENBQUMsT0FBTyxHQUFHLE9BQU8sQ0FBQztJQUN2RCxPQUF3QixJQUFJLENBQUM7QUFDL0IsQ0FBQztBQU5ELDBCQU1DIn0=