3

We're trying to use stacktrace-js with the awesome logary-js (my project) but after going through webpack it would seem it doesn't work anymore.

Here's the configuration for webpack https://github.com/logary/logary-js/blob/c7fdec752e5ce33843d458e9e6c590657005c60a/webpack.config.js

Here's the output that makes me concerned (npm run build):

> logary@2.0.2 build /Users/h/dev/haf/logary-js
> NODE_ENV=production webpack --progress --color --display-error-details --display-reasons --optimize-minimize

Hash: d1c4b6913d586c4424ce
Version: webpack 1.13.0
Time: 2263ms
        Asset     Size  Chunks             Chunk Names
    logary.js  55.2 kB       0  [emitted]  logary
logary.js.map   407 kB       0  [emitted]  logary
    + 19 hidden modules

WARNING in logary.js from UglifyJs
Side effects in initialization of unused variable promise [./src/index.js:357,8]
Side effects in initialization of unused variable Targets [./src/index.js:382,13]
Dropping side-effect-free statement [./~/jssha/src/sha.js:12,0]
Condition always true [./~/jssha/src/sha.js:37,116]
Condition always true [./~/stacktrace-js/stacktrace.js:6,0]
Dropping unreachable code [./~/stacktrace-js/stacktrace.js:8,5]
Condition always true [./~/error-stack-parser/error-stack-parser.js:6,0]
Dropping unreachable code [./~/error-stack-parser/error-stack-parser.js:8,5]
Condition always true [./~/stackframe/stackframe.js:6,0]
Dropping unreachable code [./~/stackframe/stackframe.js:8,5]
Condition always true [./~/stack-generator/stack-generator.js:6,0]
Dropping unreachable code [./~/stack-generator/stack-generator.js:8,5]
Condition always true [./~/stacktrace-gps/stacktrace-gps.js:6,0]
Dropping unreachable code [./~/stacktrace-gps/stacktrace-gps.js:8,5]

On this branch I try disable UglifyJs to no avail.

npm run test gives this output (snipped):

  stacktrace enricher
    ✓ should be a function
    ✓ should accept a message and return a function
    ✓ passes through messages without errors
    ✓ parses errors in generated errors (385ms)
    ✓ should parse errors into stack traces

So it would seem the webpack-mocha integration in dev works really well. However, when I use logary from other JS after releasing I get this output from stacktrace-js:

stacktrace-js enricher for logary-js

When it should fulfil these unit tests (which is does do when I run mocha, but not when I run it in the browser):

  const stacktrace = Middleware.stacktrace
  // snip

  it('passes through messages without errors', function() {
    const msg = Message.event('Signup');
    const res = stacktrace(logger)(msg);
    expect(res.value.event).to.equal('Signup');
    expect(res.level).to.equal('info');
    expect(res.fields).to.deep.equal({});
    expect(res.context).to.deep.equal({
      logger: 'AreaX.ComponentA',
      service: 'MyWebSite'
    });
  });

  it('parses errors in generated errors', function(done) {
    const msg = Message.eventError('Uncomfortable Error', error);
    const subjectMsg = stacktrace(logger)(msg);

    expect(expect(subjectMsg).to.eventually.be.fulfilled.then(msg => {
      expect(msg.fields).to.be.an('object');
      expect(msg.fields.errors).to.have.lengthOf(1);
      expect(msg.fields.errors[0]).to.not.equal(error);
      expect(msg.fields.errors[0]).to.be.an('Array');
    })).to.notify(done);
  });

  it('should parse errors into stack traces', function(done) {
    const msg = Message.eventError('Uncomfortable Error', error, {
            myField: 'abc'
          }),
          actual = stacktrace(logger)(msg).then(x => x.fields);

    expect(expect(Promise.all([
      actual,
      StackTrace.fromError(error)
    ])).to.eventually.be.fulfilled.then(([actualFields, expectedError]) => {
      expect(actualFields.errors[0]).to.deep.equal(expectedError);
      expect(actualFields.myField).to.equal('abc');
    })).to.notify(done);
Henrik
  • 9,303
  • 4
  • 49
  • 83

0 Answers0