7 examples of 'error stack' in JavaScript

Every line of 'error stack' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
94function checkStack(errorStack){
95 if (settings.enableStackList){
96 const stackList = lists.get("stack");
97 if (stackList.length){
98 const callingStack = parseErrorStack(errorStack);
99 return stackList.match(callingStack);
100 }
101 }
102 return false;
103}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

384function replaceStack(error, stack) {
385 let message = error.stack.split('\n')[0];
386 error.stack = [message].concat(stack.split('\n').slice(1)).join('\n');
387}
22function getStack (err) {
23 if (err.__error) return err.__error.stack
24
25 return err.stack
26}
42public static emptyStack(): Error {
43 return new Error('The stack is empty.');
44}
58export function getStack() {
59 const { stack } = new Error();
60 return stack
61 ? stack.split('\n').slice(4).map( item => item.trim() ).join( '\n' )
62 : '';
63}
49function getStack() {
50 var orig = Error.prepareStackTrace;
51 Error.prepareStackTrace = function (_, stack) {
52 return stack;
53 };
54 var err = new Error();
55 Error.captureStackTrace(err, arguments.callee);
56 var stack = err.stack;
57 Error.prepareStackTrace = orig;
58 return stack;
59}
8function getStack(e) {
9 var stack = e.stack
10
11 if (!(e instanceof Error) || stack != null) return stack
12
13 try {
14 throw e
15 } catch (e) {
16 return e.stack
17 }
18}

Related snippets