1
Vote

Extended exceptions when parsing files

description

When the JavascriptParser encounters problems, it would be really helpful, if the exception would also include the filename which caused the problem.

This could be accomplished, e.g. by adding the information in JSAnalyse.Core.Parser.JavascriptParser.Parse(string,string) [for v03 in JSAnalyse.Core/Parser/JavascriptParser.js lines 45, 50].

As a simple example, changing:

private ParserResult Parse(string javascriptContent, string fileName)
    {
        var result = new ParserResult(fileName);
        // Compile script
        _program = JintEngine.Compile(javascriptContent, true);

        if (_program != null)
        {
            // Start visitor
            _program.Accept(_visitor);

}...

to:

    private ParserResult Parse(string javascriptContent, string fileName)
    {
        var result = new ParserResult(fileName);
        // Compile script
        try{
            _program = JintEngine.Compile(javascriptContent, true);
        } catch (Jint.JintException exc){
            throw new System.Exception("Error parsing file "+fileName, exc);
        }

        if (_program != null)
        {
            // Start visitor
            try {
                _program.Accept(_visitor);
            }
            catch (Jint.JintException exc)
            {
                throw new System.Exception("Error parsing file " + fileName, exc);
            }
        }

comments