question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Better StackTraces with filtering and mapping lines

See original GitHub issue

Let us say we have the following stack trace:

    Expected 'bar' to be 'bar1'
    assert@/Users/foo/Workspace/ws/examples/browser-js/test-dist/index.js:11066:27 <- ~/expect/lib/assert.js:29:0
    toBe@/Users/foo/Workspace/ws/examples/browser-js/test-dist/index.js:8037:28 <- ~/expect/lib/Expectation.js:86:0
    /Users/foo/Workspace/ws/examples/browser-js/test-dist/index.js:7909:75 <- test/unit.ts:31:48

First I’d like to filter stack traces from ~/except. Second I want to only see the original source (the part after <-).

I could actually hack the lib/reporter.js at line 92 like this to achieve this result:

    // filter lines
    msg = msg.split('\n').filter(line => !line.match(/~\/expect\/lib/)).join('\n');
    // map lines
    msg = msg.split('\n').map(line => line.match(/\/(.*)<-/) ? line.replace(/\/(.*)<-/, '') : line).join('\n');

The result will be:

    Expected 'bar' to be 'bar1'
     test/unit.ts:31:48

Can I achieve the same behaviour with existing APIs? Or can I add this behaviour with a pull request? I could imagine to add two new fields to the karma config (e.g. mapStackTraceLine/filterStackTraceLine) so everyone can set custom filter/map rules if needed.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
IAMtheIAMcommented, Sep 21, 2017

Thanks!

So I used your example:

      formatError(msg) {

         // Uncommment this to get rid of the entire stack trace, but then you don't know what happened
         // return ''

         // filter out empty lines and node_modules
         if (!msg.trim() || /~/.test(msg)) return ''

         // indent the error beneath the it() message
         let newLine = `  ${msg}`

         if (newLine.includes('webpack:///')) {
            // remove webpack:///
            newLine = newLine.replace('webpack:///', '')

            // remove bundle location, showing only the source location
            newLine = newLine.slice(0, newLine.indexOf(' <- '))
         }

         return `${newLine}\n`
      },

It did clean it up quite a bit, But I’m still getting some weird mode_modules stuff.

Error: No provider for Http! in config/karma.entry.js (line 3185)
      _throwOrNull@node_modules/@angular/core/@angular/core.es5.js:2649:0
      _getByKeyDefault@node_modules/@angular/core/@angular/core.es5.js:2688:0
      _getByKey@node_modules/@angular/core/@angular/core.es5.js:2620:0
      get@node_modules/@angular/core/@angular/core.es5.js:2489:0
      resolveNgModuleDep@node_modules/@angular/core/@angular/core.es5.js:9481:0
      _createClass@node_modules/@angular/core/@angular/core.es5.js:9524:0
      _createProviderInstance$1@node_modules/@angular/core/@angular/core.es5.js:9492:0
      resolveNgModuleDep@node_modules/@angular/core/@angular/core.es5.js:9477:0
      _createClass@node_modules/@angular/core/@angular/core.es5.js:9532:0
      _createProviderInstance$1@node_modules/@angular/core/@angular/core.es5.js:9492:0
      resolveNgModuleDep@node_modules/@angular/core/@angular/core.es5.js:9477:0
      get@node_modules/@angular/core/@angular/core.es5.js:10569:0
      resolveDep@node_modules/@angular/core/@angular/core.es5.js:11072:0
      createClass@node_modules/@angular/core/@angular/core.es5.js:10928:0
      createDirectiveInstance@node_modules/@angular/core/@angular/core.es5.js:10756:21
      createViewNodes@node_modules/@angular/core/@angular/core.es5.js:12197:33
      createRootView@node_modules/@angular/core/@angular/core.es5.js:12092:0
      callWithDebugContext@node_modules/@angular/core/@angular/core.es5.js:13475:25
      debugCreateRootView@node_modules/@angular/core/@angular/core.es5.js:12792:0
      create@node_modules/@angular/core/@angular/core.es5.js:9864:25
      initComponent@node_modules/@angular/core/@angular/core/testing.es5.js:889:0
      invoke@node_modules/zone.js/dist/zone.js:392:0
      onInvoke@node_modules/zone.js/dist/proxy.js:79:0
      invoke@node_modules/zone.js/dist/zone.js:391:0
      onInvoke@node_modules/@angular/core/@angular/core.es5.js:3890:0
      invoke@node_modules/zone.js/dist/zone.js:391:0
      run@node_modules/zone.js/dist/zone.js:142:0
      run@node_modules/@angular/core/@angular/core.es5.js:3821:42
      createComponent@node_modules/@angular/core/@angular/core/testing.es5.js:892:0
      createComponent@node_modules/@angular/core/@angular/core/testing.es5.js:656:0
      src-test/app-components/app/app.spec.ts:52:40
      invoke@node_modules/zone.js/dist/zone.js:392:0
      onInvoke@node_modules/zone.js/dist/proxy.js:79:0
      invoke@node_modules/zone.js/dist/zone.js:391:0
      run@node_modules/zone.js/dist/zone.js:142:0
      node_modules/zone.js/dist/jasmine-patch.js:104:0
      execute@node_modules/zone.js/dist/jasmine-patch.js:132:0
      invokeTask@node_modules/zone.js/dist/zone.js:425:0
      runTask@node_modules/zone.js/dist/zone.js:192:0
      drainMicroTaskQueue@node_modules/zone.js/dist/zone.js:602:0
      run@node_modules/core-js/modules/es6.promise.js:66:0
      node_modules/core-js/modules/es6.promise.js:79:0
      flush@node_modules/core-js/modules/_microtask.js:18:0

So I modified it a little and it works!

      formatError(msg) {

         // Uncommment this to get rid of the entire stack trace, but then you don't know what happened
         // return ''

         // filter out empty lines and node_modules
         if (!msg.trim() || /~/.test(msg) || /node_modules/.test(msg)) return '' // < --- modified this line

         // indent the error beneath the it() message
         let newLine = `  ${msg}`

         if (newLine.includes('webpack:///')) {
            // remove webpack:///
            newLine = newLine.replace('webpack:///', '')

            // remove bundle location, showing only the source location
            newLine = newLine.slice(0, newLine.indexOf(' <- '))
         }

         return `${newLine}\n`
      },
  Error: No provider for Http! in config/karma.entry.js (line 3185)

Thanks a ton @levithomason!

0reactions
levithomasoncommented, Sep 20, 2017

See my response to your question here, https://github.com/rstacruz/mocha-clean/issues/5#issuecomment-331010426.

The usage changed slightly due to how the stack is passed. Each line is passed one at a time, rather than the whole stack at once.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Filter irrelevant stack trace lines in logs - Java Code Geeks
For instance in web application the stack trace shows you the complete request processing path, from HTTP socket, through filters, servlets, ...
Read more >
How to filter stacktrace frames in Logback - Stack Overflow
So I configured logback with the following not to print any stack trace line from org.something packages (e.g. org.apache , org.springframework ...
Read more >
StackTrace.JS - Framework-agnostic, micro-library for getting ...
Generate, parse, and enhance JavaScript stack traces in all web browsers ... stacktrace.js v2.0 is out, featuring ES6 support, better stack frames, and...
Read more >
Stack Trace Filter - Logstash/Gelf Loggers
logstash-gelf provides a built-in stack trace filter to filter out the noise out of stack traces. Original stack trace. javax.servlet.
Read more >
Configuring Mule Stack Traces | MuleSoft Documentation
When Mule does show stack traces, it filters out some internal class references from to produce a more readable output. You can control...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found