-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Retain partially valid structs in convert.Normalize
#1203
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ func normalizeType(typ reflect.Type, src dyn.Value) (dyn.Value, diag.Diagnostics | |
return normalizeFloat(typ, src) | ||
} | ||
|
||
return dyn.NilValue, diag.Errorf("unsupported type: %s", typ.Kind()) | ||
return dyn.InvalidValue, diag.Errorf("unsupported type: %s", typ.Kind()) | ||
} | ||
|
||
func typeMismatch(expected dyn.Kind, src dyn.Value) diag.Diagnostic { | ||
|
@@ -69,7 +69,7 @@ func normalizeStruct(typ reflect.Type, src dyn.Value) (dyn.Value, diag.Diagnosti | |
if err != nil { | ||
diags = diags.Extend(err) | ||
// Skip the element if it cannot be normalized. | ||
if err.HasError() { | ||
if !v.IsValid() { | ||
continue | ||
} | ||
} | ||
|
@@ -82,7 +82,7 @@ func normalizeStruct(typ reflect.Type, src dyn.Value) (dyn.Value, diag.Diagnosti | |
return src, diags | ||
} | ||
|
||
return dyn.NilValue, diags.Append(typeMismatch(dyn.KindMap, src)) | ||
return dyn.InvalidValue, diags.Append(typeMismatch(dyn.KindMap, src)) | ||
} | ||
|
||
func normalizeMap(typ reflect.Type, src dyn.Value) (dyn.Value, diag.Diagnostics) { | ||
|
@@ -97,7 +97,7 @@ func normalizeMap(typ reflect.Type, src dyn.Value) (dyn.Value, diag.Diagnostics) | |
if err != nil { | ||
diags = diags.Extend(err) | ||
// Skip the element if it cannot be normalized. | ||
if err.HasError() { | ||
if !v.IsValid() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notable change 2 |
||
continue | ||
} | ||
} | ||
|
@@ -110,7 +110,7 @@ func normalizeMap(typ reflect.Type, src dyn.Value) (dyn.Value, diag.Diagnostics) | |
return src, diags | ||
} | ||
|
||
return dyn.NilValue, diags.Append(typeMismatch(dyn.KindMap, src)) | ||
return dyn.InvalidValue, diags.Append(typeMismatch(dyn.KindMap, src)) | ||
} | ||
|
||
func normalizeSlice(typ reflect.Type, src dyn.Value) (dyn.Value, diag.Diagnostics) { | ||
|
@@ -125,7 +125,7 @@ func normalizeSlice(typ reflect.Type, src dyn.Value) (dyn.Value, diag.Diagnostic | |
if err != nil { | ||
diags = diags.Extend(err) | ||
// Skip the element if it cannot be normalized. | ||
if err.HasError() { | ||
if !v.IsValid() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notable change 3 |
||
continue | ||
} | ||
} | ||
|
@@ -138,7 +138,7 @@ func normalizeSlice(typ reflect.Type, src dyn.Value) (dyn.Value, diag.Diagnostic | |
return src, diags | ||
} | ||
|
||
return dyn.NilValue, diags.Append(typeMismatch(dyn.KindSequence, src)) | ||
return dyn.InvalidValue, diags.Append(typeMismatch(dyn.KindSequence, src)) | ||
} | ||
|
||
func normalizeString(typ reflect.Type, src dyn.Value) (dyn.Value, diag.Diagnostics) { | ||
|
@@ -155,7 +155,7 @@ func normalizeString(typ reflect.Type, src dyn.Value) (dyn.Value, diag.Diagnosti | |
case dyn.KindFloat: | ||
out = strconv.FormatFloat(src.MustFloat(), 'f', -1, 64) | ||
default: | ||
return dyn.NilValue, diags.Append(typeMismatch(dyn.KindString, src)) | ||
return dyn.InvalidValue, diags.Append(typeMismatch(dyn.KindString, src)) | ||
} | ||
|
||
return dyn.NewValue(out, src.Location()), diags | ||
|
@@ -177,10 +177,10 @@ func normalizeBool(typ reflect.Type, src dyn.Value) (dyn.Value, diag.Diagnostics | |
out = false | ||
default: | ||
// Cannot interpret as a boolean. | ||
return dyn.NilValue, diags.Append(typeMismatch(dyn.KindBool, src)) | ||
return dyn.InvalidValue, diags.Append(typeMismatch(dyn.KindBool, src)) | ||
} | ||
default: | ||
return dyn.NilValue, diags.Append(typeMismatch(dyn.KindBool, src)) | ||
return dyn.InvalidValue, diags.Append(typeMismatch(dyn.KindBool, src)) | ||
} | ||
|
||
return dyn.NewValue(out, src.Location()), diags | ||
|
@@ -197,14 +197,14 @@ func normalizeInt(typ reflect.Type, src dyn.Value) (dyn.Value, diag.Diagnostics) | |
var err error | ||
out, err = strconv.ParseInt(src.MustString(), 10, 64) | ||
if err != nil { | ||
return dyn.NilValue, diags.Append(diag.Diagnostic{ | ||
return dyn.InvalidValue, diags.Append(diag.Diagnostic{ | ||
Severity: diag.Error, | ||
Summary: fmt.Sprintf("cannot parse %q as an integer", src.MustString()), | ||
Location: src.Location(), | ||
}) | ||
} | ||
default: | ||
return dyn.NilValue, diags.Append(typeMismatch(dyn.KindInt, src)) | ||
return dyn.InvalidValue, diags.Append(typeMismatch(dyn.KindInt, src)) | ||
} | ||
|
||
return dyn.NewValue(out, src.Location()), diags | ||
|
@@ -221,14 +221,14 @@ func normalizeFloat(typ reflect.Type, src dyn.Value) (dyn.Value, diag.Diagnostic | |
var err error | ||
out, err = strconv.ParseFloat(src.MustString(), 64) | ||
if err != nil { | ||
return dyn.NilValue, diags.Append(diag.Diagnostic{ | ||
return dyn.InvalidValue, diags.Append(diag.Diagnostic{ | ||
Severity: diag.Error, | ||
Summary: fmt.Sprintf("cannot parse %q as a floating point number", src.MustString()), | ||
Location: src.Location(), | ||
}) | ||
} | ||
default: | ||
return dyn.NilValue, diags.Append(typeMismatch(dyn.KindFloat, src)) | ||
return dyn.InvalidValue, diags.Append(typeMismatch(dyn.KindFloat, src)) | ||
} | ||
|
||
return dyn.NewValue(out, src.Location()), diags | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notable change 1