Update error messages

This commit is contained in:
Svilen Markov 2024-11-29 21:12:10 +00:00
parent 2c03316f86
commit a816d1a913

View File

@ -102,12 +102,12 @@ var includePattern = regexp.MustCompile(`(?m)^(\s*)!include:\s*(.+)$`)
func parseYAMLIncludes(mainFilePath string) ([]byte, map[string]struct{}, error) { func parseYAMLIncludes(mainFilePath string) ([]byte, map[string]struct{}, error) {
mainFileContents, err := os.ReadFile(mainFilePath) mainFileContents, err := os.ReadFile(mainFilePath)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("could not read main YAML file: %w", err) return nil, nil, fmt.Errorf("reading main YAML file: %w", err)
} }
mainFileAbsPath, err := filepath.Abs(mainFilePath) mainFileAbsPath, err := filepath.Abs(mainFilePath)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("could not get absolute path of main YAML file: %w", err) return nil, nil, fmt.Errorf("getting absolute path of main YAML file: %w", err)
} }
mainFileDir := filepath.Dir(mainFileAbsPath) mainFileDir := filepath.Dir(mainFileAbsPath)
@ -136,7 +136,7 @@ func parseYAMLIncludes(mainFilePath string) ([]byte, map[string]struct{}, error)
fileContents, err = os.ReadFile(includeFilePath) fileContents, err = os.ReadFile(includeFilePath)
if err != nil { if err != nil {
includesLastErr = fmt.Errorf("could not read included file: %w", err) includesLastErr = fmt.Errorf("reading included file %s: %w", includeFilePath, err)
return nil return nil
} }
@ -160,12 +160,12 @@ func configFilesWatcher(
) (func() error, error) { ) (func() error, error) {
watcher, err := fsnotify.NewWatcher() watcher, err := fsnotify.NewWatcher()
if err != nil { if err != nil {
return nil, fmt.Errorf("could not create watcher: %w", err) return nil, fmt.Errorf("creating watcher: %w", err)
} }
if err = watcher.Add(mainFilePath); err != nil { if err = watcher.Add(mainFilePath); err != nil {
watcher.Close() watcher.Close()
return nil, fmt.Errorf("could not add main file to watcher: %w", err) return nil, fmt.Errorf("adding main file to watcher: %w", err)
} }
updateWatchedIncludes := func(previousIncludes map[string]struct{}, newIncludes map[string]struct{}) { updateWatchedIncludes := func(previousIncludes map[string]struct{}, newIncludes map[string]struct{}) {
@ -192,7 +192,7 @@ func configFilesWatcher(
checkForContentChangesBeforeCallback := func() { checkForContentChangesBeforeCallback := func() {
currentContents, currentIncludes, err := parseYAMLIncludes(mainFilePath) currentContents, currentIncludes, err := parseYAMLIncludes(mainFilePath)
if err != nil { if err != nil {
onErr(fmt.Errorf("could not parse main file contents for comparison: %w", err)) onErr(fmt.Errorf("parsing main file contents for comparison: %w", err))
return return
} }