-
Notifications
You must be signed in to change notification settings - Fork 281
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
add console.error for async TranscriptLogger.logActivity() impl in TranscriptLoggerMiddleware #669
Conversation
…anscriptLoggerMiddleware
Pull Request Test Coverage Report for Build 2391
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just one comment - for consideration
// tslint:disable-next-line:no-console | ||
console.error('TranscriptLoggerMiddleware logActivity failed', err); | ||
}); | ||
} | ||
} catch (err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something of a nit.
If this err object is of type Error (which it should be but isn't necessarily) then this line will do a toString which will write only a subset of the information being carried to the console.
Wouldn't it therefore be more correct to explicitly check if it was of type Error and if it was then print out more of the fields, otherwise just toString()? (Incidentally, if I remember correctly I don't think JSON.stringify will work on Error.)
In this particular case I'm not sure this matters to much because its just the console. But something to consider in general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this?
try {
const activity: Activity = this.transcript.shift();
// Comments comments comments...
const logActivityResult = this.logger.logActivity(activity);
// Comments comments comments...
if (logActivityResult.catch(err => {
this.transcriptLoggerErrorHandler(err);
});
} catch (err) {
this.transcriptLoggerErrorHandler(err);
}
private transcriptLoggerErrorHandler(err: Error|Any): void {
// tslint:disable:no-console
if (err instanceof Error) {
console.error(`TranscriptLoggerMiddleware logActivity failed: "${ err.message }"`);
console.error(err.stack);
} else {
console.error(`TranscriptLoggerMiddleware logActivity failed: "${ JSON.stringify(err) }"`);
}
// tslint:enable:no-console
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice
Fixes #383
Description
Previously, if asynchronous TranscriptLogger.logActivity() implementations threw an error in TranscriptLgogerMiddleware, an UnhandledPromiseRejectionWarning would occur. This PR changes TranscriptLoggerMiddleware to instead console.error the error thrown via an appended
catch()
.Specific Changes