Skip to content

Commit

Permalink
Report ambiguous syscfg configuration
Browse files Browse the repository at this point in the history
This addresses: #565
  • Loading branch information
m-gorecki committed Aug 22, 2024
1 parent ce21d33 commit 85d67b9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
4 changes: 3 additions & 1 deletion newt/cli/target_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ func pkgVarSliceString(pack *pkg.LocalPackage, key string) string {
func amendSysCfg(value string, t *target.Target) error {
// Get the current syscfg.vals name-value pairs
sysVals, err := t.Package().SyscfgY.GetValStringMapString("syscfg.vals", nil)
util.OneTimeWarningError(err)
if err != nil {
return err
}

// Convert the input syscfg into name-value pairs
amendSysVals, err := syscfg.KeyValueFromStr(value)
Expand Down
4 changes: 3 additions & 1 deletion newt/syscfg/syscfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,9 @@ func (cfg *Cfg) readValsOnce(lpkg *pkg.LocalPackage,
lsettings := cfg.settingsForLpkg(lpkg, settings)

values, err := yc.GetValStringMap("syscfg.vals", lsettings)
util.OneTimeWarningError(err)
if err != nil {
return err
}

for k, v := range values {
switch v.(type) {
Expand Down
21 changes: 18 additions & 3 deletions newt/ycfg/ycfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,13 @@ func (yc *YCfg) GetStringMap(
Expr: mapEntry.Expr,
}

// XXX: Report collisions?
if _, exists := result[k]; exists {
if (entry.Value != result[k].Value) && (result[k].Expr != nil) {
return nil, fmt.Errorf("Setting %s collision - two conditions true:\n[%s, %s]\n"+
"Conflicting file: %s",
k, entry.Expr.String(), result[k].Expr.String(), yc.name)
}
}
result[k] = entry
}
}
Expand Down Expand Up @@ -607,7 +613,13 @@ func (yc *YCfg) GetStringMapString(key string,
Expr: mapEntry.Expr,
}

// XXX: Report collisions?
if _, exists := result[k]; exists {
if (entry.Value != result[k].Value) && (result[k].Expr != nil) {
return nil, fmt.Errorf("Setting %s collision - two conditions true:\n[%s, %s]\n"+
"Conflicting file: %s",
k, entry.Expr.String(), result[k].Expr.String(), yc.name)
}
}
result[k] = entry
}
}
Expand All @@ -623,6 +635,9 @@ func (yc *YCfg) GetValStringMapString(key string,
settings *cfgv.Settings) (map[string]string, error) {

entryMap, getErr := yc.GetStringMapString(key, settings)
if getErr != nil {
return nil, getErr
}

valMap := make(map[string]string, len(entryMap))
for k, v := range entryMap {
Expand All @@ -631,7 +646,7 @@ func (yc *YCfg) GetValStringMapString(key string,
}
}

return valMap, getErr
return valMap, nil
}

// FullName calculates a node's name with the following form:
Expand Down

0 comments on commit 85d67b9

Please sign in to comment.