-
Notifications
You must be signed in to change notification settings - Fork 133
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
Fix: Uncaught exceptions cause a silent exit #721
Conversation
humanReadableUnhandledException: true, | ||
level: 'error', | ||
showLevel: true, | ||
}), |
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.
Is this different from console.error
? Should we remove that?
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.
Do you mean from this line:
markbind/src/lib/markbind/src/parser.js
Line 82 in 1686253
this._onError = this._options.errorHandler || console.error; |
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.
No, this line:
Line 33 in 669325b
console.log(chalk.red(`error: ${text}`)); |
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.
The current mechanism of logging is as follows:
We are using logger.js
functions to print messages to the console with console.log()
statements and a winston-daily-rotate-file transport set to level debug
that writes messages to a log file.
Nunjucks errors were not being logged to the console because we are not calling logger.error()
explicitly in nunjucks.renderString()
(as we don't have error handlers for these calls). Other errors do get printed to the console because we call logger.error()
when we catch them.
However, nunjucks errors were being printed to the log file because of the winston-daily-rotate-file transport.
If we want to remove console.error
(and other console.log
statements in logger.js
), then we should use the winston console transport with the level set to debug
. There is an option to use custom formats (color, etc.) too.
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.
Correct me if I am wrong, nunjucks
is actually using winston-daily-rotate-file
internally? I am struggling to see how the pieces are connected here.
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.
Our application does use winston through the logger, but we have also configured winston to handle logging uncaught exceptions.
Line 15 in 6bbe1fa
handleExceptions: true, |
That's how nunjucks errors were being logged to the log file, because we don't have error handlers for the
renderString()
calls.
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.
-
Thanks for checking this. It answers the question originally raised by @yamgent.
-
How about this?
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 tested this.
// index.js logger.error('hi');
console.log(chalk.red(`error: ${text}`)); // console.log(chalk.red(`error: ${text}`)); Let's set
winston.transports.Console
level to'info'
and then removeconsole.log
inlogger.error
,logger.warn
andlogger.info
.
Sorry for the confusion regarding the console.error
reference! I didn't realise logger.error
was using console.log
.
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.
Let's set
winston.transports.Console
level to'info'
and then removeconsole.log
inlogger.error
,logger.warn
andlogger.info
.
May I do these changes in this PR itself?
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.
Yes please.
* Change winston's console logging level to info * Remove console.log statements from error, warn, info to avoid duplication in logs
|
Is that an actual error? |
Yep, it happens when you run |
Looks like I have accidentally discovered something worth fixing. :P Never mind my original comment then; I thought it was something that was previously printed on our own on the log. |
What is the purpose of this pull request? (put "X" next to an item, remove the rest)
• [X] Bug fix
Fixes #265, #610.
What is the rationale for this request?
Errors in building files with nunjucks (as well as uncaught exceptions) were causing a silent exit. This information should be shown to the user on the console. It was previously shown in the log file only.
What changes did you make? (Give an overview)
Added a new Console transport to winston for logging errors to the console.
Also passed the path parameter to
nunjucks.renderString()
as errors thrown by Nunjucks were not showing the file paths.Provide some example code that this change will affect:
Add the following statement to any file:
Console output on
markbind build
: