MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / getStack

Function getStack

src/lib/console.js:602–635  ·  view source on GitHub ↗

* Gets the stack trace of the current call * @param {Error} error * @returns

(error, skip = false)

Source from the content-addressed store, hash-verified

600 * @returns
601 */
602 function getStack(error, skip = false) {
603 if (error === null) {
604 error = new Error();
605 }
606 let stack = error.stack.split("\n");
607 if (!skip) stack.splice(1, 1);
608 let regExecRes = /<([^>]*)>:(\d+):(\d+)/.exec(stack[1]) || [];
609 if (!regExecRes.length) {
610 const errorInfo = stack[1]?.split("/").pop();
611 regExecRes = /(.+?):(\d+):(\d+)/.exec(errorInfo) || [];
612 }
613 let src = "";
614 const location = regExecRes[1];
615 const lineno = regExecRes[2];
616 const colno = regExecRes[3];
617
618 if (location && lineno) {
619 src = escapeHTML(`${location} ${lineno}${colno ? ":" + colno : ""}`);
620 } else {
621 const res = /\((.*)\)/.exec(stack[1]);
622 src = res && res[1] ? res[1] : "";
623 }
624 const index = src.indexOf(")");
625 src = src
626 .split("/")
627 .pop()
628 .substring(0, index < 0 ? undefined : index);
629 if (src.length > 50) src = "..." + src.substring(src.length - 50);
630
631 return {
632 location: src,
633 stack: stack.join("\n"),
634 };
635 }
636
637 function execute(code) {
638 let res = null;

Callers 15

assertFunction · 0.85
countFunction · 0.85
debugFunction · 0.85
dirFunction · 0.85
dirxmlFunction · 0.85
errorFunction · 0.85
groupFunction · 0.85
groupCollapsedFunction · 0.85
groupEndFunction · 0.85
infoFunction · 0.85
logFunction · 0.85
tableFunction · 0.85

Calls 2

escapeHTMLFunction · 0.85
execMethod · 0.65

Tested by

no test coverage detected