Skip to content

Commit

Permalink
bake: do not attempt to unmarshal empty attributes
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Dec 2, 2024
1 parent 71c7889 commit c962c23
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion bake/bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,9 @@ type arrValue[B any] interface {
func parseArrValue[T any, PT arrValue[T]](s []string) ([]*T, error) {
outputs := make([]*T, 0, len(s))
for _, text := range s {
if text == "" {
continue
}
output := new(T)
if err := PT(output).UnmarshalText([]byte(text)); err != nil {
return nil, err
Expand All @@ -1594,7 +1597,9 @@ func parseArrValue[T any, PT arrValue[T]](s []string) ([]*T, error) {
func parseCacheArrValues(s []string) ([]*buildflags.CacheOptionsEntry, error) {
outs := make([]*buildflags.CacheOptionsEntry, 0, len(s))
for _, in := range s {
if !strings.Contains(in, "=") {
if in == "" {
continue
} else if !strings.Contains(in, "=") {
// This is ref only format. Each field in the CSV is its own entry.
fields, err := csvvalue.Fields(in, nil)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion util/buildflags/cty.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,9 @@ func unmarshalTextFallback[V encoding.TextUnmarshaler](in cty.Value, v V, inErr

// Conversion was successful. Use UnmarshalText on the string and return any
// errors associated with that.
return v.UnmarshalText([]byte(conv.AsString()))
convstr := conv.AsString()
if convstr == "" {
return nil
}
return v.UnmarshalText([]byte(convstr))
}

0 comments on commit c962c23

Please sign in to comment.