Add user-facing notifications for fatal errors with configuration option
Description
Fatal errors (module loading failures, invalid config files) were only logged to the output channel, making them easy to miss. Users had no visible indication when Prettier stopped working.
Changes
New NotificationService (src/NotificationService.ts)
- Shows error notifications with actionable buttons (View Output, Open Settings)
- Detects if prettier is in package.json but not installed → suggests running
npm install - Deduplicates notifications per session to prevent spam
- Respects user preference via configuration setting
Configuration Option (prettier.enableErrorNotifications)
- New setting that defaults to
true - Allows users to disable error notifications if preferred
- When disabled, errors are still logged to the output channel
ModuleResolver Integration
- Module load failures → notification with package.json detection
- Invalid
prettierPathsetting → notification with "Open Settings" button - Invalid/unresolvable config files → notification
Example
When prettier is listed in package.json but not installed:
[Error Notification]
Prettier: Failed to load module. Prettier is listed in package.json
but could not be loaded. Please run npm install (or yarn/pnpm install).
[View Output] [Dismiss]
When prettierPath setting is invalid:
[Error Notification]
Prettier: The 'prettierPath' setting does not reference a valid
Prettier installation. Please check your settings.
[Open Settings] [View Output] [Dismiss]
Not included by design: Notifications for format errors in user code (these remain as problems/diagnostics only).
Related Issue
Fixes #3882
Type of Change
- [x] New feature (non-breaking change that adds functionality)
Checklist
- [x] I have read the CONTRIBUTING guidelines
- [x] My code follows the code style of this project (
npm run lintpasses) - [x] I have run
npm run prettierto format my code - [ ] I have added/updated tests that prove my fix or feature works
- [ ] All new and existing tests pass (
npm test) - [ ] I have updated the CHANGELOG.md with a summary of my changes
Original prompt
This section details on the original issue you should resolve
<issue_title>Use notifications for errors</issue_title> <issue_description>Currently, fatal errors like if we cannot load the prettier module, issues with the config file, problems loading modules, etc. are printed to the output and the status bar icon changes in some cases, but otherwise it is very hard to know an error happened. We should use VSCode's notifications for errors and warnings that are fatal - we dont want to be too aggressive (i think for formatting errors due to invalid code on the file being formatted for example, a notification is too aggressive - for that we should use problems, but that is a separate issue.
Update the code to show actionable and useful error or warning notifications on errors. For example if we cannot load the prettier module because it isn't installed locally, we should notify the user of the error and tell them that we found prettier in the package.json, but it is not installed and they need to install it.</issue_description>
Comments on the Issue (you are @copilot in this section)
- Fixes prettier/prettier-vscode#3882
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
@copilot lets add a configuration option enableErrorNotifications that is defaulted to true. This will allow users to disable the notifications if they want.
@copilot lets add a configuration option
enableErrorNotificationsthat is defaulted to true. This will allow users to disable the notifications if they want.
Done in ea2289b. Added the prettier.enableErrorNotifications configuration option that defaults to true. Users can now disable error notifications by setting this to false in their VS Code settings. When disabled, errors will only be logged to the output channel.