Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
feat(errors): do not display a popup for "undefined" error messages
Browse files Browse the repository at this point in the history
These messages were very annoying because many plugins do not properly define these and it tends to
spam the user.
  • Loading branch information
robwise committed Aug 19, 2018
1 parent a7e5187 commit d6a25f5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dist/executePrettier/handleError.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const setErrorMessageInLinter = ({ editor, bufferRange, error }) => linter.setMe

const isSyntaxError = _.overSome([_.flow(_.get('error.loc.start.line'), _.isInteger), _.flow(_.get('error.loc.line'), _.isInteger)]);

const isUndefinedError = _.flow(_.get('error.message'),
// $FlowIssue
_.matches('undefined'));

const isFilePathPresent = _.flow(_.get('editor'), getCurrentFilePath, _.negate(_.isNil));

const displayErrorInPopup = args => console.error(args.error) || // eslint-disable-line no-console
Expand All @@ -35,6 +39,7 @@ addErrorNotification(`prettier-atom failed: ${args.error.message}`, {
dismissable: true
});

const handleError = _.flow(_.cond([[_.overEvery([isSyntaxError, isFilePathPresent]), setErrorMessageInLinter], [_.stubTrue, displayErrorInPopup]]));
const handleError = _.flow(_.cond([[_.overEvery([isSyntaxError, isFilePathPresent]), setErrorMessageInLinter], [isUndefinedError, args => console.error('Prettier encountered an error:', args.error)], // eslint-disable-line no-console
[_.stubTrue, displayErrorInPopup]]));

module.exports = handleError;
7 changes: 7 additions & 0 deletions src/executePrettier/handleError.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ const isSyntaxError: HandleErrorArgs => boolean = _.overSome([
),
]);

const isUndefinedError: HandleErrorArgs => boolean = _.flow(
_.get('error.message'),
// $FlowIssue
_.matches('undefined'),
);

const isFilePathPresent: HandleErrorArgs => boolean = _.flow(
_.get('editor'),
getCurrentFilePath,
Expand All @@ -68,6 +74,7 @@ const displayErrorInPopup = (args: HandleErrorArgs) =>
const handleError: HandleErrorArgs => void = _.flow(
_.cond([
[_.overEvery([isSyntaxError, isFilePathPresent]), setErrorMessageInLinter],
[isUndefinedError, args => console.error('Prettier encountered an error:', args.error)], // eslint-disable-line no-console
[_.stubTrue, displayErrorInPopup],
]),
);
Expand Down
11 changes: 11 additions & 0 deletions src/executePrettier/handleError.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,14 @@ it('displays errors in a popup if there is no filepath (linter requires a filepa
expect(addErrorNotification).toHaveBeenCalled();
expect(console.error).toHaveBeenCalledWith(error); // eslint-disable-line no-console
});

it('only logs, but does not display "Undefined" errors', () => {
// plugins cause lots of these and they're too spammy
getCurrentFilePath.mockImplementation(() => null);
const error = new Error('undefined');

handleError({ error });

expect(addErrorNotification).not.toHaveBeenCalled();
expect(console.error).toHaveBeenCalledWith('Prettier encountered an error:', error); // eslint-disable-line no-console
});

0 comments on commit d6a25f5

Please sign in to comment.