-
Notifications
You must be signed in to change notification settings - Fork 37
fix(logging): ensure callback executes even if Application Insights throws #791
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,4 +63,32 @@ describe('logger', function () { | |
| expect(trackTrace.firstCall.args[0].message).to.contain('plain error without stack') | ||
| expect(trackTrace.firstCall.args[0].severity).to.equal('Error') | ||
| }) | ||
|
|
||
| it('still calls callback if trackTrace throws', done => { | ||
| const consoleError = sinon.stub(console, 'error') | ||
| trackTrace.throws(new Error('AI unavailable')) | ||
| const logger = factory({ aiClient }) | ||
| logger.info('test message') | ||
| clock.runAll() | ||
| setImmediate(() => { | ||
| expect(trackTrace.callCount).to.equal(1) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This checks that I tried breaking the fix to see what these catch. If you skip
const cb = sinon.spy()
new ApplicationInsightsTransport({ aiClient }).log({ level: 'info', message: 'x' }, cb)
clock.runAll()
expect(cb.calledOnce).to.equal(true)Then the test fails if the callback ever stops running. Same idea for the |
||
| consoleError.restore() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Putting the stub in a sinon sandbox and resetting it in |
||
| done() | ||
| }) | ||
| clock.runAll() | ||
| }) | ||
|
|
||
| it('still calls callback if trackException throws', done => { | ||
| const consoleError = sinon.stub(console, 'error') | ||
| trackException.throws(new Error('AI unavailable')) | ||
| const logger = factory({ aiClient }) | ||
| logger.log({ level: 'error', message: 'boom', stack: 'Error: boom\n at test:1:1' }) | ||
| clock.runAll() | ||
| setImmediate(() => { | ||
| expect(trackException.callCount).to.equal(1) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
| consoleError.restore() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
| done() | ||
| }) | ||
| clock.runAll() | ||
| }) | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.