Skip to content

Commit

Permalink
pad_utils: New warnWithStack() function
Browse files Browse the repository at this point in the history
  • Loading branch information
rhansen committed Nov 14, 2021
1 parent 1bbe0d9 commit eae814f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/static/js/pad_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ const urlRegex = (() => {
})();

const padutils = {
/**
* Prints a warning message followed by a stack trace (to make it easier to figure out what code
* is using the deprecated function).
*
* Most browsers include UI widget to examine the stack at the time of the warning, but this
* includes the stack in the log message for a couple of reasons:
* - This makes it possible to see the stack if the code runs in Node.js.
* - Users are more likely to paste the stack in bug reports they might file.
*
* @param {...*} args - Passed to `console.warn`, with a stack trace appended.
*/
warnWithStack: (...args) => {
const err = new Error();
if (Error.captureStackTrace) Error.captureStackTrace(err, padutils.warnWithStack);
err.name = '';
if (err.stack) args.push(err.stack);
console.warn(...args);
},

escapeHtml: (x) => Security.escapeHTML(String(x)),
uniqueId: () => {
const pad = require('./pad').pad; // Sidestep circular dependency
Expand Down

0 comments on commit eae814f

Please sign in to comment.