JSFiddle - React, Tailwind, and code Playground

by justjohn

JavaScript

//                             //
//  ┗(-.- )┓ ┏(-.-)┓ ┏( -.-)┛  //
//  -------------------------  //
//      ERROR PARTY TIME       //
//                             //

var ErrorWrapper = function(msg, fileurl, line, column, err) {
    var name = null;
    if (msg) {
        var parts = msg.split(":");
        if (parts.length > 0) {
            name = parts.shift();
            msg = parts.join(":").trim();
        }
    }

    if (err) {
        this.name = err.name || name;
        this.msg = err.message || msg;
        this.file = err.fileName || fileurl;
        this.line = err.lineNumber || line;
        this.column = err.columnNumber || column;
        this.stack = this.processStack(err.stack);
    } else {
        this.name = name;
        this.msg = msg;
        this.file = fileurl;
        this.line = line;
        this.column = column;
    }
};

ErrorWrapper.prototype.processStack = function(stack) {
    if (!stack) return null;

    var lines = stack.split("\n");
    lines = lines.map(function(line) {
        return line.trim();
    });
    
    console.log(lines);

    return stack;
};

window.onerror = function(msg, fileurl, line, column, err) {
    var wrapper = new ErrorWrapper(msg, fileurl, line, column, err);
    console.log("args");
    console.log(arguments);

    console.log("Error:");
    console.log(wrapper);
};


function foo() {
    afdsg
}

foo();