From 6973cd1e69977c8143415c383514736aac7a12c7 Mon Sep 17 00:00:00 2001 From: Yasmin Valim Date: Tue, 16 Apr 2024 15:47:59 -0300 Subject: [PATCH] fix: add new errors --- config/shared/errors/errors.go | 3 ++- config/v3_5_experimental/types/config.go | 8 ++++---- config/v3_5_experimental/types/config_test.go | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/config/shared/errors/errors.go b/config/shared/errors/errors.go index 1f3ec0a958..12cf27d10f 100644 --- a/config/shared/errors/errors.go +++ b/config/shared/errors/errors.go @@ -85,7 +85,8 @@ var ( ErrInvalidProxy = errors.New("proxies must be http(s)") ErrInsecureProxy = errors.New("insecure plaintext HTTP proxy specified for HTTPS resources") ErrPathConflictsSystemd = errors.New("path conflicts with systemd unit or dropin") - ErrPathConflictsParentDir = errors.New("path conflicts with parent directory of another file, link, or directory") + ErrPathAlreadyExists = errors.New("path already exists") + ErrMisslabeledDir = errors.New("parent directory path matches configured file, check path, and ensure parent directory is configured") // Systemd section errors ErrInvalidSystemdExt = errors.New("invalid systemd unit extension") diff --git a/config/v3_5_experimental/types/config.go b/config/v3_5_experimental/types/config.go index 262e278370..a64bd46877 100644 --- a/config/v3_5_experimental/types/config.go +++ b/config/v3_5_experimental/types/config.go @@ -81,17 +81,17 @@ func (cfg Config) validateParents(c path.ContextPath) report.Report { r := report.Report{} for i, f := range cfg.Storage.Files { - r = handlePathConflict(f.Path, "files", i, c, r, errors.ErrPathConflictsParentDir) + r = handlePathConflict(f.Path, "files", i, c, r, errors.ErrPathAlreadyExists) addPathAndEntry(f.Path, "files", &entries) } for i, d := range cfg.Storage.Directories { - r = handlePathConflict(d.Path, "directories", i, c, r, errors.ErrPathConflictsParentDir) + r = handlePathConflict(d.Path, "directories", i, c, r, errors.ErrPathAlreadyExists) addPathAndEntry(d.Path, "directories", &entries) } for i, l := range cfg.Storage.Links { - r = handlePathConflict(l.Path, "links", i, c, r, errors.ErrPathConflictsParentDir) + r = handlePathConflict(l.Path, "links", i, c, r, errors.ErrPathAlreadyExists) addPathAndEntry(l.Path, "links", &entries) } @@ -102,7 +102,7 @@ func (cfg Config) validateParents(c path.ContextPath) report.Report { for i, entry := range entries { if i > 0 && isWithin(entry.Path, entries[i-1].Path) { if entries[i-1].Field != "directories" { - r.AddOnError(c.Append("storage", entry.Field, i, "path"), errors.ErrPathConflictsParentDir) + r.AddOnError(c.Append("storage", entry.Field, i, "path"), errors.ErrMisslabeledDir) return r } } diff --git a/config/v3_5_experimental/types/config_test.go b/config/v3_5_experimental/types/config_test.go index 73ae779d52..362371dbdb 100644 --- a/config/v3_5_experimental/types/config_test.go +++ b/config/v3_5_experimental/types/config_test.go @@ -194,7 +194,7 @@ func TestConfigValidation(t *testing.T) { }, }, }, - out: errors.ErrPathConflictsParentDir, + out: errors.ErrMisslabeledDir, at: path.New("json", "storage", "files", 1, "path"), }, @@ -210,7 +210,7 @@ func TestConfigValidation(t *testing.T) { }, }, }, - out: errors.ErrPathConflictsParentDir, + out: errors.ErrMisslabeledDir, at: path.New("json", "storage", "links", 1, "path"), }, @@ -226,7 +226,7 @@ func TestConfigValidation(t *testing.T) { }, }, }, - out: errors.ErrPathConflictsParentDir, + out: errors.ErrMisslabeledDir, at: path.New("json", "storage", "directories", 1, "path"), },