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

Incorrectly parsing code #38

Open
eriwen opened this issue Aug 12, 2017 · 0 comments
Open

Incorrectly parsing code #38

eriwen opened this issue Aug 12, 2017 · 0 comments

Comments

@eriwen
Copy link
Member

eriwen commented Aug 12, 2017

@tarr11 commented on Mon Jun 12 2017

I am using Function to parse and eval some code in the browser. I would like to use StackTraceJS to show errors to my users in the code editor. My code is minified using Webpack/Uglify, but user code is not. User code is executed in a sandboxed iframe.

Expected Behavior

I expect that StackFrameJS should parse "anonymous" errors correctly.

Current Behavior

StackFrameJS does not parse anonymous errors like below, nor return the correct line number.

Sample User Code (should throw an error):
image

My code is executed like this

    let runFunction = function (p) {
      let f = null;
      try {
        f = Function("p", code)
        f(p);
      } catch (error) {
          StackTrace.fromError(error).then(sr => {
          window.parent.postMessage({sr, type: "err"}, "*");
        })

      }
    }
   // call runFunction
  runFunction(...);

The stack trace looks like this (in Chrome)

ReferenceError: hi is not defined
    at eval (eval at runFunction (http://localhost:8080/packs/iframe.js:5669:21), <anonymous>:4:9)
    at runFunction (http://localhost:8080/packs/iframe.js:5670:17)
    at e.Sketch.sketch.attachFunction (http://localhost:8080/packs/iframe.js:5722:17)
    at e.Sketch.attach (eval at webpackJsonp.679.module.exports (http://localhost:8080/packs/iframe.js:11868:8), <anonymous>:43:267)
    at Ir (eval at webpackJsonp.679.module.exports (http://localhost:8080/packs/iframe.js:11868:8), <anonymous>:1417:89)
    at eval (eval at webpackJsonp.679.module.exports (http://localhost:8080/packs/iframe.js:11868:8), <anonymous>:1415:106)"

The parsed stack trace looks like this (first line)
image

Steps to Reproduce (for bugs)

Context

I am trying to use StackTrace to parse and show JS errors to a user in a browser editor (Monaco)

Your Environment

  • stacktrace.js version: 2.0
  • Browser Name and version: Chrome 58
  • Operating System and version (desktop or mobile): OS X Sierra 10.12.5

Possible Solution

Suggest improving the parser to handle nested / anonymous stack traces


@eriwen commented on Sat Aug 12 2017

Thanks for the issue. Error parsing is done in error-stack-parser, so I'm moving the issue to that project.

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

No branches or pull requests

1 participant