Skip to content

Commit

Permalink
fix(vite): prevent crashes by catching reload handler errors
Browse files Browse the repository at this point in the history
  • Loading branch information
innocenzi committed Feb 25, 2022
1 parent b9239ee commit ff18d7d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion vite-plugin-laravel/src/reload.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Plugin, ViteDevServer } from 'vite'
import makeDebugger from 'debug'
import { warn } from './utils'
import { Options, WatchOptions } from './types'

const PREFIX = 'vite:laravel:reload'
Expand Down Expand Up @@ -49,7 +50,12 @@ export const reload = (options: Options = {}): Plugin => {
watchOptions.input.forEach((value) => {
if (value.condition(file)) {
debug(`${file} changed, applying its handler`)
value.handle({ file, server })
try {
value.handle({ file, server })
} catch (error: any) {
warn(PREFIX, `Handler failed for ${file}: ${error.message}`)
debug('Full error:', error)
}
}
})
}
Expand Down

0 comments on commit ff18d7d

Please # to comment.