stacktrace.js icon indicating copy to clipboard operation
stacktrace.js copied to clipboard

Function names missing

Open NathanGloyn opened this issue 7 years ago • 1 comments

Expected Behavior

When calling StackTrace.fromError expect stack trace frames to have the correct function name

Current Behavior

Majority of function names are null in the stack trace frames

Steps to Reproduce (for bugs)

Using the following error.stack

"Error: BOOM! at AService.addFile (https://localhost:5555/app/service/aservice.js:122:15) at CreateService.addExisting (https://localhost:5555/app/service/create.service.js:39:29) at EditFormComponent.newFileUploaded (https://localhost:5555/app/features/edit-form.component.js:88:36) at EditFormComponent.fileUploadCompleted (https://localhost:5555/app/features/edit-form.component.js:70:18) at _View_EditFormComponent2._handle_fileUploadCompleteEvent_279_0 (/SettingsModule/EditFormComponent/component.ngfactory.js:2401:39) at eval (https://localhost:5555/node_modules/@angular/core/bundles/core.umd.js:9437:28) at SafeSubscriber.schedulerFn [as _next] (https://localhost:5555/node_modules/@angular/core/bundles/core.umd.js:5964:40) at SafeSubscriber.__tryOrUnsub (https://localhost:5555/node_modules/rxjs/Subscriber.js:223:16) at SafeSubscriber.next (https://localhost:5555/node_modules/rxjs/Subscriber.js:172:22) at Subscriber._next (https://localhost:5555/node_modules/rxjs/Subscriber.js:125:26)"

Most of the stack frames output have null for function name, the array as JSON is: "[{"functionName":"null","fileName":"https://localhost:5555/app/program/service/activities/app/program/service/activities/activity.service.ts","lineNumber":179,"columnNumber":10},{"functionName":"null","fileName":"https://localhost:5555/app/program/features/program-settings/activities/ser…am/features/program-settings/activities/service/create-activity.service.ts","lineNumber":51,"columnNumber":28},{"functionName":"null","fileName":"https://localhost:5555/app/program/features/program-settings/activities/act…/program-settings/activities/activity-form/edit-activity-form.component.ts","lineNumber":93,"columnNumber":31},{"functionName":"null","fileName":"https://localhost:5555/app/program/features/program-settings/activities/act…/program-settings/activities/activity-form/edit-activity-form.component.ts","lineNumber":73,"columnNumber":11},{"functionName":"_View_EditActivityFormComponent2._handle_fileUploadCompleteEvent_279_0","fileName":"/ProgramSettingsModule/EditActivityFormComponent/component.ngfactory.js","lineNumber":2401,"columnNumber":39,"source":" at _View_EditActivityFormComponent2._handle_fileUploadCompleteEvent_279_0 (/ProgramSettingsModule/EditActivityFormComponent/component.ngfactory.js:2401:39)"},{"functionName":"eval","fileName":"https://localhost:5555/node_modules/@angular/core/bundles/core.umd.js","lineNumber":9437,"columnNumber":28,"source":" at eval (https://localhost:5555/node_modules/@angular/core/bundles/core.umd.js:9437:28)"},{"functionName":"SafeSubscriber.schedulerFn [as _next]","fileName":"https://localhost:5555/node_modules/@angular/core/bundles/core.umd.js","lineNumber":5964,"columnNumber":40,"source":" at SafeSubscriber.schedulerFn [as _next] (https://localhost:5555/node_modules/@angular/core/bundles/core.umd.js:5964:40)"},{"functionName":"null","fileName":"src/Subscriber.ts","lineNumber":238,"columnNumber":9},{"functionName":"null","fileName":"src/Subscriber.ts","lineNumber":190,"columnNumber":13},{"functionName":"null","fileName":"src/Subscriber.ts","lineNumber":135,"columnNumber":21}]"

Context

StackTrace is being used in an Angular 2 ErrorHandler implementation. At this point we will not be able to use StackTrace in our code as without the function names it doesn't provide us what we need

Your Environment

  • stacktrace.js version: 1.3.1
  • Browser Name and version: Chrome 56.0.2924.87 (64-bit)
  • Operating System and version (desktop or mobile): desktop
  • Link to your project: unable to link to actual project, but we are based off of the angular seed project using TypeScript for dev which the build process then converts to js with sourcemap

Possible Solution

I checked out the ErrorParser repo and modified a test to have the stack listed here and it correctly parsed the error.

I then checked out stacktrace and attempted to alter a test to try and isolate the issue but ran into other problems where by long file paths or a file path that started with a / would cause the jasmine test to timeout.

stepping through the code it appears that the error occurs when whilst calling gps.pinpoint(sf) inside stacktrace.js, I followed the code through and in getMappedLocation in stacktrace-gps.js upto the call to this._get(fileName) the stack frame still has the function name but by the time the resolve function in fromError is called the function name is gone and I couldn't see where it was changed.

NathanGloyn avatar Mar 21 '17 17:03 NathanGloyn

With fresh eyes this morning I've found the root cause of the issue.

In _extractLocationInfoFromSourceMap when calling mapConsumer.originalPositionFor and creating the loc object the name property is always null.

Looking at the code lead me to SourceMapConsumer_parseMappings to see what the source map parsing was producing and basically the source map doesn't provide a name.

The upshot of the map not having a function name is that the name that was generated by the ErrorParser is overwritten by the lack of name from the source map.

At this point I'm wondering if the original function name should be passed to extractLocationInfoFromSourceMap then if the source map returns null for the name you could at least give the stack frame the existing name we have.

NathanGloyn avatar Mar 22 '17 09:03 NathanGloyn