Factor out some code into a helper function

This commit is contained in:
Andrew Ayer 2023-02-20 10:05:04 -05:00
parent fd0a2a4d44
commit 8b7cef7f61
1 changed files with 10 additions and 5 deletions

View File

@ -103,14 +103,19 @@ func defaultScriptDir() string {
return filepath.Join(defaultConfigDir(), "hooks.d") return filepath.Join(defaultConfigDir(), "hooks.d")
} }
func simplifyError(err error) error {
var pathErr *fs.PathError
if errors.As(err, &pathErr) {
return pathErr.Err
}
return err
}
func readWatchListFile(filename string) (monitor.WatchList, error) { func readWatchListFile(filename string) (monitor.WatchList, error) {
file, err := os.Open(filename) file, err := os.Open(filename)
if err != nil { if err != nil {
var pathErr *fs.PathError return nil, simplifyError(err)
if errors.As(err, &pathErr) {
err = pathErr.Err
}
return nil, err
} }
defer file.Close() defer file.Close()
return monitor.ReadWatchList(file) return monitor.ReadWatchList(file)