8000 Incorrectly parsing code · Issue #194 · stacktracejs/stacktrace.js · GitHub
[go: up one dir, main page]

Skip to content
Incorrectly parsing code #194
Closed
Closed
@tarr11

Description

@tarr11

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0