Skip to content

Commit

Permalink
Merge pull request #295 from arexon/fix-file-watching-error-reporting
Browse files Browse the repository at this point in the history
Handle errors during file watching
  • Loading branch information
Nusiq authored Sep 25, 2024
2 parents fd8b410 + 3650095 commit e51e376
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 8 additions & 3 deletions regolith/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ type RunContext struct {
// of the change ("rp", "bp" or "data"), which may be used to handle
// some interruptions differently.
interruptionChannel chan string

// fileWatchingErrorChannel is used to pass any errors that may occur during
// file watching.
fileWatchingErrorChannel chan error
}

// GetProfile returns the Profile structure from the context.
Expand Down Expand Up @@ -59,14 +63,14 @@ func (c *RunContext) StartWatchingSourceFiles() error {
}

c.interruptionChannel = make(chan string)
c.fileWatchingErrorChannel = make(chan error)
yieldChanges := func(
watcher *DirWatcher, sourceName string,
) {
for {
err := watcher.WaitForChangeGroup(
100, c.interruptionChannel, sourceName)
err := watcher.WaitForChangeGroup(100, c.interruptionChannel, sourceName)
if err != nil {
return
c.fileWatchingErrorChannel <- err
}
}
}
Expand Down Expand Up @@ -99,6 +103,7 @@ func (c *RunContext) StartWatchingSourceFiles() error {
return burrito.WrapError(err, "Could not create data watcher.")
}
}

return nil
}

Expand Down
9 changes: 8 additions & 1 deletion regolith/main_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ func Watch(profileName string, debug bool) error {
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)

// Run the profile
context.StartWatchingSourceFiles()
err = context.StartWatchingSourceFiles()
if err != nil {
return burrito.PassError(err)
}
for { // Loop until program termination (CTRL+C)
err = RunProfile(*context)
if err != nil {
Expand All @@ -313,6 +316,10 @@ func Watch(profileName string, debug bool) error {
// AwaitInterruption locks the goroutine with the interruption channel until
// the Config is interrupted and returns the interruption message.
Logger.Warn("Restarting...")
case err := <-context.fileWatchingErrorChannel:
if err != nil {
return burrito.WrapError(err, "Encountered an error during file watching")
}
case <-sigChan:
return sessionLockErr // Return the error from the defer function
}
Expand Down

0 comments on commit e51e376

Please sign in to comment.