Path: blob/trunk/third_party/closure/goog/debug/errorcontext.js
4505 views
/**1* @license2* Copyright The Closure Library Authors.3* SPDX-License-Identifier: Apache-2.04*/56/**7* @fileoverview Provides methods dealing with context on error objects.8*/910goog.provide('goog.debug.errorcontext');111213/**14* Adds key-value context to the error.15* @param {!Error} err The error to add context to.16* @param {string} contextKey Key for the context to be added.17* @param {string} contextValue Value for the context to be added.18*/19goog.debug.errorcontext.addErrorContext = function(20err, contextKey, contextValue) {21'use strict';22if (!err[goog.debug.errorcontext.CONTEXT_KEY_]) {23err[goog.debug.errorcontext.CONTEXT_KEY_] = {};24}25err[goog.debug.errorcontext.CONTEXT_KEY_][contextKey] = contextValue;26};272829/**30* @param {!Error} err The error to get context from.31* @return {!Object<string, string>} The context of the provided error.32*/33goog.debug.errorcontext.getErrorContext = function(err) {34'use strict';35return err[goog.debug.errorcontext.CONTEXT_KEY_] || {};36};373839// TODO(user): convert this to a Symbol once goog.debug.ErrorReporter is40// able to use ES6.41/** @private @const {string} */42goog.debug.errorcontext.CONTEXT_KEY_ = '__closure__error__context__984382';434445