Skip to content

add watcher error reporting in theme fs#7317

Open
EvilGenius13 wants to merge 1 commit intomainfrom
jf-on-error
Open

add watcher error reporting in theme fs#7317
EvilGenius13 wants to merge 1 commit intomainfrom
jf-on-error

Conversation

@EvilGenius13
Copy link
Copy Markdown
Contributor

WHY are these changes introduced?

We have had some reports of files not syncing, and there's the possibility that the watcher is throwing an error we're silently swallowing.

WHAT is this pull request doing?

add a .on('error') branch which will output a debug log and record it to our monorail events.

How to test your changes?

I don't have a good way of replicating a real OS-level failure for this but feel free to run the test I added.

Post-release steps

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes
  • I've considered analytics changes to measure impact
  • The change is user-facing, so I've added a changelog entry with pnpm changeset add

@EvilGenius13 EvilGenius13 requested review from a team as code owners April 15, 2026 19:19
Copilot AI review requested due to automatic review settings April 15, 2026 19:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves observability for theme file watching by surfacing Chokidar watcher errors via logging and runtime analytics, helping diagnose reports of files not syncing.

Changes:

  • Add a Chokidar .on('error') handler to log watcher errors and emit an analytics event.
  • Add a unit test covering watcher error handling and analytics emission.
  • Mock recordEvent in tests to assert telemetry behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/theme/src/cli/utilities/theme-fs.ts Adds watcher error handler that logs and records an analytics event.
packages/theme/src/cli/utilities/theme-fs.test.ts Adds test coverage for watcher error emission and mocks analytics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +874 to +887
test('outputs a warning when the watcher emits an error', async () => {
// Given
const {outputWarn} = await import('@shopify/cli-kit/node/output')
const themeFileSystem = mountThemeFileSystem(root)
await themeFileSystem.ready()
await themeFileSystem.startWatcher(themeId, adminSession)

// When
const watcher = chokidar.watch('') as EventEmitter
watcher.emit('error', new Error('EMFILE: too many open files'))

// Then
expect(outputWarn).toHaveBeenCalledWith('File watcher error: Error: EMFILE: too many open files')
expect(recordEvent).toHaveBeenCalledWith('theme-service:file-watcher:error')
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test expects outputWarn to be called, but the implementation logs watcher errors with outputDebug. As written, this test will fail—either update the expectation to outputDebug (and import it here) or change the implementation to use outputWarn so code and test match the intended user-facing behavior.

Copilot uses AI. Check for mistakes.
Comment on lines +351 to +354
.on('error', (error) => {
outputDebug(`File watcher error: ${error}`)
recordEvent('theme-service:file-watcher:error')
})
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recordEvent('theme-service:file-watcher:error') loses the error context (message/category) that would help diagnose OS-level watcher failures. Consider also (or instead) calling recordError(error) from @shopify/cli-kit/node/analytics, and when logging include error.stack when available so debug output contains actionable details.

Copilot uses AI. Check for mistakes.
.on('unlink', queueFsEvent.bind(null, 'unlink'))
.on('error', (error) => {
outputDebug(`File watcher error: ${error}`)
recordEvent('theme-service:file-watcher:error')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use recordError, too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants