Skip to content

Commit

Permalink
fix: add new errors
Browse files Browse the repository at this point in the history
  • Loading branch information
yasminvalim committed Apr 16, 2024
1 parent bc6be5f commit 6973cd1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion config/shared/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions config/v3_5_experimental/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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
}
}
Expand Down
6 changes: 3 additions & 3 deletions config/v3_5_experimental/types/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func TestConfigValidation(t *testing.T) {
},
},
},
out: errors.ErrPathConflictsParentDir,
out: errors.ErrMisslabeledDir,
at: path.New("json", "storage", "files", 1, "path"),
},

Expand All @@ -210,7 +210,7 @@ func TestConfigValidation(t *testing.T) {
},
},
},
out: errors.ErrPathConflictsParentDir,
out: errors.ErrMisslabeledDir,
at: path.New("json", "storage", "links", 1, "path"),
},

Expand All @@ -226,7 +226,7 @@ func TestConfigValidation(t *testing.T) {
},
},
},
out: errors.ErrPathConflictsParentDir,
out: errors.ErrMisslabeledDir,
at: path.New("json", "storage", "directories", 1, "path"),
},

Expand Down

0 comments on commit 6973cd1

Please sign in to comment.