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

How do I get the javascript error trace? #28

Closed
sleungcy opened this issue Apr 12, 2017 · 2 comments
Closed

How do I get the javascript error trace? #28

sleungcy opened this issue Apr 12, 2017 · 2 comments

Comments

@sleungcy
Copy link

sleungcy commented Apr 12, 2017

Hi,

I am trying to debug this issue Object has no memeber 'assign'

How can I get the stacktrace when there is an error in the javascript?
I am using e.stack, but it's giving me an undefined value.

JS code:
result.error = "Render Error: " + e + "\n\t\tStackTrace: " + e.stack + "."

outcome:
Render Error: TypeError: Object has no member 'assign'
StackTrace: undefined.

@dop251
Copy link
Owner

dop251 commented Apr 13, 2017

Currently the only way to get the stack trace is by converting the returned error into *goja.Exception and calling its String() method, e.g.:

func TestStacktrace(t *testing.T) {
	const SCRIPT = `
	function f() {
		throw new Error("Test");
	}

	f();
	`

	vm := New()
	_, err := vm.RunString(SCRIPT)
	if ex, ok := err.(*Exception); ok {
		t.Log(ex.String())
	}
}

This will print

Error: Test
			at f (<eval>:3:9(4))
			at <eval>:6:3(7)

Error.stack property is not part of any specification, however it seems to be present in all major implementations, so I may add it in the future.

As for Object.assign, see #24

@sleungcy
Copy link
Author

Thanks, I got the problem fixed.

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

No branches or pull requests

2 participants