Share template reference tracking error

Author: leviyuan, Date: 2020-01-28 20:39:09
Tags:

How to use: First, refer to this template library Add $.fileLineMark ((mainbar, 35)) to each script file. The first parameter: file name. The second parameter: the line number of this line of code in the file. This is the only way to ensure that this line of code is executed before the error is tracked. Finally, in the policy code, add main = $.tryfunc ((main) to ensure that all calls go through try.

When a policy error is reported, there is automatically a red line indicating which file is on which line.

Principle: The way to host the loading of the js code is to load all the js code, including the class library, into one large file; find the location of each file in the large file, and when the last error is reported, reverse the corresponding line number of the specific error.

img


var fileStartLine = []
$.fileLineMark = function(file, line) {
    try{a=a+1}catch(ex){
        var markline = parseInt(ex.stack.split('\n')[3].split('(__FILE__:')[1].split(')')[0])
        fileStartLine.push([file, markline-line])
        fileStartLine.sort(function(a, b){
            return b[1] - a[1]
        })
    }
}

$.tryfunc = function(func) {
    return function(a,b,c,d,e,f,g,h,i,j,k,l,m,n) {
        try {
            return func(a,b,c,d,e,f,g,h,i,j,k,l,m,n)
        } catch(ex) {
            if (ex.message == "execution timeout") {
                Log("忽略机器人停止指令")
                throw ex
                return
            }

            var line = parseInt(ex.stack.split('\n')[2].split('(__FILE__:')[1].split(')')[0])
            for (var ii = 0; ii < fileStartLine.length; ii++) {
                if (line > fileStartLine[ii][1]) {
                    Log("catch error at " + fileStartLine[ii][0] + ":" + (line-fileStartLine[ii][1])+"#ff0000")
                    break
                }
            }

            throw ex
        }
    }
}

function onTick() {

}

function main() {
    $.fileLineMark("main", 41)
    onTick = $.tryfunc(onTick)
    
    while(true){
        onTick()
        Sleep(1000)
    }
}


More

The grassThis is interesting, look.

The grassI can do it, but I didn't think about it at the time.

leviyuanHaha, reverse thinking about what you guys are doing internally - not exactly accurate, but helpful, huh?