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

Commit

Permalink
Show error for JS plugin watcher
Browse files Browse the repository at this point in the history
Signed-off-by: Vikram Yadav <yvikram@vmware.com>

#1273
  • Loading branch information
Vikram Yadav committed Aug 23, 2021
1 parent 5163d0f commit 0666cae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/2776-xtreme-vikram-yadav
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
logged better errors for JS plugin watcher
27 changes: 16 additions & 11 deletions pkg/plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,18 @@ func (m *Manager) watchJS(ctx context.Context) {
}
}()

watchedDirs := []string{}
for _, dir := range dirs {
if err := watcher.Add(dir); err != nil {
logger.Warnf("unable to add %s to JavaScript plugin watcher", dir)
logger.Warnf("Unable to add %s to JavaScript plugin watcher. Error: %s\n", dir, err)
} else {
watchedDirs = append(watchedDirs, dir)
}
}

logger.Infof("watching for new JavaScript plugins in %q", dirs)
if len(watchedDirs) > 0 {
logger.Infof("Watching for new JavaScript plugins in %q\n", dirs)
}

writeEvents := make(map[string]bool)
updatePlugin := func(name string) {
Expand All @@ -392,26 +397,26 @@ func (m *Manager) watchJS(ctx context.Context) {
case <-ctx.Done():
logger.Infof("context cancelled shutting down JavaScript plugin watcher.")
return
case event, ok := <-watcher.Events:
case ev, ok := <-watcher.Events:
if !ok {
logger.Errorf("bad event returned from JavaScript plugin watcher")
return
}
if event.Op&(fsnotify.Chmod|fsnotify.Write|fsnotify.Create) == fsnotify.Chmod {
if ev.Op&(fsnotify.Chmod|fsnotify.Write|fsnotify.Create) == fsnotify.Chmod {
continue
}
if IsJavaScriptPlugin(event.Name) {
if event.Op&fsnotify.Remove == fsnotify.Remove {
jsPlugin, ok := m.store.GetJS(event.Name)
if IsJavaScriptPlugin(ev.Name) {
if ev.Op&fsnotify.Remove == fsnotify.Remove {
jsPlugin, ok := m.store.GetJS(ev.Name)
if ok {
if err := m.unregisterJSPlugin(ctx, jsPlugin); err != nil {
logger.Errorf("unregistering: %w", err)
}
m.store.RemoveJS(event.Name)
logger.Infof("removing: JavaScript plugin: %s", event.Name)
m.store.RemoveJS(ev.Name)
logger.Infof("removing: JavaScript plugin: %s", ev.Name)
}
} else if event.Op&fsnotify.Write == fsnotify.Write {
writeEvents[event.Name] = true
} else if ev.Op&fsnotify.Write == fsnotify.Write {
writeEvents[ev.Name] = true
}
}
case err, ok := <-watcher.Errors:
Expand Down

0 comments on commit 0666cae

Please sign in to comment.