-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 try/catch when writing yarn-error.log #2095
Conversation
If yarn is lacking write access, the `fs.writeFileSync()` method throws an uncaught exception that blocks further execution. Simply catching it and allowing further exection provides desired behaviour by giving the user feedback and having yarn terminate. Fixes #2094
fs.writeFileSync(errorLoc, log.join('\n\n') + '\n'); | ||
try { | ||
fs.writeFileSync(errorLoc, log.join('\n\n') + '\n'); | ||
} 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 should probably at least console.error
or something rather than silently ignoring it.
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.
Maybe something like reporter.error('Could not write yarn-error.log: ' + err)
(with proper localized string)
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 thing is, #346 already handles it marvelously. It just needs to get there. I was thinking to rather piggyback on that one, rather than handling it explicitly. But I can of course change into doing so.
reporter.info(reporter.lang('bugReport', errorLoc)); | ||
} catch (err) { | ||
if (err.code === 'EACCES') { | ||
reporter.error(reporter.lang('noFilePermission', err.path)); |
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.
@Daniel15 About doing this instead then?
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.
We don't use console.error anywhere, better to keep to reporter.error anyway.
How about you wrap only fs.writeFileSync into try/catch?
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 need for console.error
- try/catch too broad
Seems to have been solved by #1592 and this can be closed. |
Summary
If yarn is lacking write access, the
fs.writeFileSync()
method throws anuncaught exception that blocks further execution.
Simply catching it and allowing further exection provides desired behaviour by
giving the user feedback and having yarn terminate.
Test plan
now results in
Previously it just kept hanging forever.
Fixes #2094