Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Information about the function where the error occurred is lost #188

Open
Taritsyn opened this issue Aug 15, 2020 · 2 comments
Open

Information about the function where the error occurred is lost #188

Taritsyn opened this issue Aug 15, 2020 · 2 comments
Labels

Comments

@Taritsyn
Copy link
Contributor

Hello, Paul!

If you run the following console application by using the latest version of Jurassic (2f1eb7b):

using System;

using Jurassic;
using Jurassic.Library;

namespace TestJurassicJavaScriptException
{
    class Program
    {
        static void Main(string[] args)
        {
            var engine = new ScriptEngine();
            var source = new StringScriptSource(@"function foo(x, y) {
    var z = x + y;
    if (z > 20) {
        bar();
    }
}

(function (foo) {
    var a = 8;
    var b = 15;

    foo(a, b);
})(foo);",
            "functions.js");

            try
            {
                engine.Execute(source);
            }
            catch (JavaScriptException e)
            {
                Console.WriteLine("During working of JavaScript engine an error occurred.");
                Console.WriteLine();
                Console.WriteLine("Message: {0}", e.Message);
                Console.WriteLine("Name: {0}", e.Name);
                Console.WriteLine("Source path: {0}", e.SourcePath ?? "null");
                Console.WriteLine("Line number: {0}", e.LineNumber);
                Console.WriteLine("Function name: {0}", e.FunctionName);

                var errorValue = e.ErrorObject as ErrorInstance;
                if (errorValue != null)
                {
                    Console.WriteLine("Stack: {0}", errorValue.Stack);
                }
            }

            Console.ReadLine();
        }
    }
}

Then you will see that information about the function where the error occurred is lost.

Current version (2f1eb7b):

…
Function name:
Stack: ReferenceError: bar is not defined.
    at functions.js:4
    at anonymous (functions.js:12)
    at functions.js:8

Previous version (14b9886):

…
Function name: foo
Stack: ReferenceError: bar is not defined
    at foo (functions.js:4)
    at anonymous (functions.js:12)
    at functions.js:8
@Taritsyn
Copy link
Contributor Author

ping

@paulbartrum
Copy link
Owner

I'm not happy with the way stack traces work now, so it's on my radar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants