Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/third_party/closure/goog/debug/errorcontext.js
4505 views
1
/**
2
* @license
3
* Copyright The Closure Library Authors.
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
/**
8
* @fileoverview Provides methods dealing with context on error objects.
9
*/
10
11
goog.provide('goog.debug.errorcontext');
12
13
14
/**
15
* Adds key-value context to the error.
16
* @param {!Error} err The error to add context to.
17
* @param {string} contextKey Key for the context to be added.
18
* @param {string} contextValue Value for the context to be added.
19
*/
20
goog.debug.errorcontext.addErrorContext = function(
21
err, contextKey, contextValue) {
22
'use strict';
23
if (!err[goog.debug.errorcontext.CONTEXT_KEY_]) {
24
err[goog.debug.errorcontext.CONTEXT_KEY_] = {};
25
}
26
err[goog.debug.errorcontext.CONTEXT_KEY_][contextKey] = contextValue;
27
};
28
29
30
/**
31
* @param {!Error} err The error to get context from.
32
* @return {!Object<string, string>} The context of the provided error.
33
*/
34
goog.debug.errorcontext.getErrorContext = function(err) {
35
'use strict';
36
return err[goog.debug.errorcontext.CONTEXT_KEY_] || {};
37
};
38
39
40
// TODO(user): convert this to a Symbol once goog.debug.ErrorReporter is
41
// able to use ES6.
42
/** @private @const {string} */
43
goog.debug.errorcontext.CONTEXT_KEY_ = '__closure__error__context__984382';
44
45