diff --git a/stdlib/universe/typeconv.go b/stdlib/universe/typeconv.go index e2fb95b5be..13703b931f 100644 --- a/stdlib/universe/typeconv.go +++ b/stdlib/universe/typeconv.go @@ -374,6 +374,9 @@ var byteConv = values.NewFunction( } else if v.Type().Nature() == semantic.Dynamic { v = v.Dynamic().Inner() } + if v.IsNull() { + v = values.Null + } switch v.Type().Nature() { case semantic.String: diff --git a/stdlib/universe/typeconv_test.go b/stdlib/universe/typeconv_test.go index 9a15a8d6fa..ed0a822d90 100644 --- a/stdlib/universe/typeconv_test.go +++ b/stdlib/universe/typeconv_test.go @@ -10,6 +10,7 @@ import ( "github.com/influxdata/flux/dependencies/dependenciestest" "github.com/influxdata/flux/dependency" "github.com/influxdata/flux/memory" + "github.com/influxdata/flux/semantic" "github.com/influxdata/flux/values" ) @@ -786,3 +787,17 @@ func TestTypeconv_Duration(t *testing.T) { }) } } + +func TestTypeconv_Bytes_NullString(t *testing.T) { + myMap := map[string]values.Value{ + "v": values.NewNull(semantic.BasicString), + } + args := values.NewObjectWithValues(myMap) + c := byteConv + ctx, deps := dependency.Inject(context.Background(), dependenciestest.Default()) + defer deps.Finish() + _, err := c.Call(ctx, args) + if err == nil || err.Error() != "cannot convert null to bytes" { + t.Errorf(`Expected error "cannot convert null to bytes", got %q`, err) + } +}