Make normalization return warnings instead of errors (#1334)

## Changes

Errors in normalization mean hard failure as of #1319.

We currently allow malformed configurations and ignore the malformed
fields and should continue to do so.

## Tests

* Tests pass.
* No calls to `diag.Errorf` from `libs/dyn`
This commit is contained in:
Pieter Noordhuis 2024-04-03 13:14:23 +02:00 committed by GitHub
parent a95b1c7dcf
commit b4e2645942
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 16 deletions

View File

@ -72,7 +72,7 @@ func nullWarning(expected dyn.Kind, src dyn.Value, path dyn.Path) diag.Diagnosti
func typeMismatch(expected dyn.Kind, src dyn.Value, path dyn.Path) diag.Diagnostic {
return diag.Diagnostic{
Severity: diag.Error,
Severity: diag.Warning,
Summary: fmt.Sprintf("expected %s, found %s", expected, src.Kind()),
Location: src.Location(),
Path: path,
@ -300,7 +300,7 @@ func (n normalizeOptions) normalizeInt(typ reflect.Type, src dyn.Value, path dyn
}
return dyn.InvalidValue, diags.Append(diag.Diagnostic{
Severity: diag.Error,
Severity: diag.Warning,
Summary: fmt.Sprintf("cannot parse %q as an integer", src.MustString()),
Location: src.Location(),
Path: path,
@ -333,7 +333,7 @@ func (n normalizeOptions) normalizeFloat(typ reflect.Type, src dyn.Value, path d
}
return dyn.InvalidValue, diags.Append(diag.Diagnostic{
Severity: diag.Error,
Severity: diag.Warning,
Summary: fmt.Sprintf("cannot parse %q as a floating point number", src.MustString()),
Location: src.Location(),
Path: path,

View File

@ -40,7 +40,7 @@ func TestNormalizeStructElementDiagnostic(t *testing.T) {
vout, err := Normalize(typ, vin)
assert.Len(t, err, 1)
assert.Equal(t, diag.Diagnostic{
Severity: diag.Error,
Severity: diag.Warning,
Summary: `expected string, found map`,
Location: dyn.Location{},
Path: dyn.NewPath(dyn.Key("bar")),
@ -100,7 +100,7 @@ func TestNormalizeStructError(t *testing.T) {
_, err := Normalize(typ, vin)
assert.Len(t, err, 1)
assert.Equal(t, diag.Diagnostic{
Severity: diag.Error,
Severity: diag.Warning,
Summary: `expected map, found string`,
Location: vin.Get("foo").Location(),
Path: dyn.EmptyPath,
@ -245,7 +245,7 @@ func TestNormalizeMapElementDiagnostic(t *testing.T) {
vout, err := Normalize(typ, vin)
assert.Len(t, err, 1)
assert.Equal(t, diag.Diagnostic{
Severity: diag.Error,
Severity: diag.Warning,
Summary: `expected string, found map`,
Location: dyn.Location{},
Path: dyn.NewPath(dyn.Key("bar")),
@ -271,7 +271,7 @@ func TestNormalizeMapError(t *testing.T) {
_, err := Normalize(typ, vin)
assert.Len(t, err, 1)
assert.Equal(t, diag.Diagnostic{
Severity: diag.Error,
Severity: diag.Warning,
Summary: `expected map, found string`,
Location: vin.Location(),
Path: dyn.EmptyPath,
@ -335,7 +335,7 @@ func TestNormalizeSliceElementDiagnostic(t *testing.T) {
vout, err := Normalize(typ, vin)
assert.Len(t, err, 1)
assert.Equal(t, diag.Diagnostic{
Severity: diag.Error,
Severity: diag.Warning,
Summary: `expected string, found map`,
Location: dyn.Location{},
Path: dyn.NewPath(dyn.Index(2)),
@ -359,7 +359,7 @@ func TestNormalizeSliceError(t *testing.T) {
_, err := Normalize(typ, vin)
assert.Len(t, err, 1)
assert.Equal(t, diag.Diagnostic{
Severity: diag.Error,
Severity: diag.Warning,
Summary: `expected sequence, found string`,
Location: vin.Location(),
Path: dyn.EmptyPath,
@ -451,7 +451,7 @@ func TestNormalizeStringError(t *testing.T) {
_, err := Normalize(&typ, vin)
assert.Len(t, err, 1)
assert.Equal(t, diag.Diagnostic{
Severity: diag.Error,
Severity: diag.Warning,
Summary: `expected string, found map`,
Location: dyn.Location{},
Path: dyn.EmptyPath,
@ -514,7 +514,7 @@ func TestNormalizeBoolFromStringError(t *testing.T) {
_, err := Normalize(&typ, vin)
assert.Len(t, err, 1)
assert.Equal(t, diag.Diagnostic{
Severity: diag.Error,
Severity: diag.Warning,
Summary: `expected bool, found string`,
Location: vin.Location(),
Path: dyn.EmptyPath,
@ -527,7 +527,7 @@ func TestNormalizeBoolError(t *testing.T) {
_, err := Normalize(&typ, vin)
assert.Len(t, err, 1)
assert.Equal(t, diag.Diagnostic{
Severity: diag.Error,
Severity: diag.Warning,
Summary: `expected bool, found map`,
Location: dyn.Location{},
Path: dyn.EmptyPath,
@ -577,7 +577,7 @@ func TestNormalizeIntFromStringError(t *testing.T) {
_, err := Normalize(&typ, vin)
assert.Len(t, err, 1)
assert.Equal(t, diag.Diagnostic{
Severity: diag.Error,
Severity: diag.Warning,
Summary: `cannot parse "abc" as an integer`,
Location: vin.Location(),
Path: dyn.EmptyPath,
@ -590,7 +590,7 @@ func TestNormalizeIntError(t *testing.T) {
_, err := Normalize(&typ, vin)
assert.Len(t, err, 1)
assert.Equal(t, diag.Diagnostic{
Severity: diag.Error,
Severity: diag.Warning,
Summary: `expected int, found map`,
Location: dyn.Location{},
Path: dyn.EmptyPath,
@ -640,7 +640,7 @@ func TestNormalizeFloatFromStringError(t *testing.T) {
_, err := Normalize(&typ, vin)
assert.Len(t, err, 1)
assert.Equal(t, diag.Diagnostic{
Severity: diag.Error,
Severity: diag.Warning,
Summary: `cannot parse "abc" as a floating point number`,
Location: vin.Location(),
Path: dyn.EmptyPath,
@ -653,7 +653,7 @@ func TestNormalizeFloatError(t *testing.T) {
_, err := Normalize(&typ, vin)
assert.Len(t, err, 1)
assert.Equal(t, diag.Diagnostic{
Severity: diag.Error,
Severity: diag.Warning,
Summary: `expected float, found map`,
Location: dyn.Location{},
Path: dyn.EmptyPath,