From 02bd5344b9002a83979edf2183dcbf659d0f79f4 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sun, 27 Oct 2024 12:05:48 -0400 Subject: [PATCH] Static-check fixes from @lespea #1657, batch 5/n (#1707) * Static-check fixes from @lespea #1657, batch 2/n * Static-check fixes from @lespea #1657, batch 3/n * Static-check fixes from @lespea #1657, batch 4/n * Static-check fixes from @lespea #1657, batch 5/n --- pkg/dsl/cst/udf.go | 3 +++ pkg/input/pseudo_reader_gen.go | 1 - pkg/lib/halfpipe.go | 6 +++++ pkg/mlrval/mlrval_get_test.go | 44 +++++++++++++++++----------------- pkg/mlrval/mlrval_json.go | 5 ++-- 5 files changed, 34 insertions(+), 25 deletions(-) diff --git a/pkg/dsl/cst/udf.go b/pkg/dsl/cst/udf.go index e1544d7b2e..f3550669e4 100644 --- a/pkg/dsl/cst/udf.go +++ b/pkg/dsl/cst/udf.go @@ -495,6 +495,9 @@ func (root *RootNode) BuildUDF( "function return value", returnValueTypeName, ) + if err != nil { + return nil, err + } lib.InternalCodingErrorIf(parameterListASTNode.Type != dsl.NodeTypeParameterList) lib.InternalCodingErrorIf(parameterListASTNode.Children == nil) diff --git a/pkg/input/pseudo_reader_gen.go b/pkg/input/pseudo_reader_gen.go index 495a6dab7d..e847b59ab5 100644 --- a/pkg/input/pseudo_reader_gen.go +++ b/pkg/input/pseudo_reader_gen.go @@ -113,7 +113,6 @@ func (reader *PseudoReaderGen) process( if recordsAndContexts.Len() > 0 { readerChannel <- recordsAndContexts - recordsAndContexts = list.New() } } diff --git a/pkg/lib/halfpipe.go b/pkg/lib/halfpipe.go index 040896a002..3b926ef3fb 100644 --- a/pkg/lib/halfpipe.go +++ b/pkg/lib/halfpipe.go @@ -21,6 +21,9 @@ import ( func OpenOutboundHalfPipe(commandString string) (*os.File, error) { readPipe, writePipe, err := os.Pipe() + if err != nil { + return nil, err + } var procAttr os.ProcAttr procAttr.Files = []*os.File{ @@ -56,6 +59,9 @@ func OpenOutboundHalfPipe(commandString string) (*os.File, error) { func OpenInboundHalfPipe(commandString string) (*os.File, error) { readPipe, writePipe, err := os.Pipe() + if err != nil { + return nil, err + } var procAttr os.ProcAttr procAttr.Files = []*os.File{ diff --git a/pkg/mlrval/mlrval_get_test.go b/pkg/mlrval/mlrval_get_test.go index 9107fbdc90..90abc85981 100644 --- a/pkg/mlrval/mlrval_get_test.go +++ b/pkg/mlrval/mlrval_get_test.go @@ -12,23 +12,23 @@ import ( func TestGetString(t *testing.T) { mv := FromInferredType("234") - stringval, ok := mv.GetStringValue() + _, ok := mv.GetStringValue() assert.False(t, ok) mv = FromDeferredType("234") - stringval, ok = mv.GetStringValue() + _, ok = mv.GetStringValue() assert.False(t, ok) mv = FromInferredType("234.5") - stringval, ok = mv.GetStringValue() + _, ok = mv.GetStringValue() assert.False(t, ok) mv = FromDeferredType("234.5") - stringval, ok = mv.GetStringValue() + _, ok = mv.GetStringValue() assert.False(t, ok) mv = FromInferredType("abc") - stringval, ok = mv.GetStringValue() + stringval, ok := mv.GetStringValue() assert.Equal(t, "abc", stringval) assert.True(t, ok) @@ -60,33 +60,33 @@ func TestGetIntValue(t *testing.T) { assert.True(t, ok) mv = FromInferredType("123.4") - intval, ok = mv.GetIntValue() + _, ok = mv.GetIntValue() assert.False(t, ok) mv = FromDeferredType("123.4") - intval, ok = mv.GetIntValue() + _, ok = mv.GetIntValue() assert.False(t, ok) mv = FromInferredType("abc") - intval, ok = mv.GetIntValue() + _, ok = mv.GetIntValue() assert.False(t, ok) mv = FromDeferredType("abc") - intval, ok = mv.GetIntValue() + _, ok = mv.GetIntValue() assert.False(t, ok) } func TestGetFloatValue(t *testing.T) { mv := FromInferredType("234") - floatval, ok := mv.GetFloatValue() + _, ok := mv.GetFloatValue() assert.False(t, ok) mv = FromDeferredType("234") - floatval, ok = mv.GetFloatValue() + _, ok = mv.GetFloatValue() assert.False(t, ok) mv = FromInferredType("234.5") - floatval, ok = mv.GetFloatValue() + floatval, ok := mv.GetFloatValue() assert.Equal(t, 234.5, floatval) assert.True(t, ok) @@ -96,11 +96,11 @@ func TestGetFloatValue(t *testing.T) { assert.True(t, ok) mv = FromInferredType("abc") - floatval, ok = mv.GetFloatValue() + _, ok = mv.GetFloatValue() assert.False(t, ok) mv = FromDeferredType("abc") - floatval, ok = mv.GetFloatValue() + _, ok = mv.GetFloatValue() assert.False(t, ok) } @@ -126,38 +126,38 @@ func TestGetNumericToFloatValue(t *testing.T) { assert.True(t, ok) mv = FromInferredType("abc") - floatval, ok = mv.GetNumericToFloatValue() + _, ok = mv.GetNumericToFloatValue() assert.False(t, ok) mv = FromDeferredType("abc") - floatval, ok = mv.GetNumericToFloatValue() + _, ok = mv.GetNumericToFloatValue() assert.False(t, ok) } func TestGetBoolValue(t *testing.T) { mv := FromInferredType("234") - boolval, ok := mv.GetBoolValue() + _, ok := mv.GetBoolValue() assert.False(t, ok) mv = FromDeferredType("234") - boolval, ok = mv.GetBoolValue() + _, ok = mv.GetBoolValue() assert.False(t, ok) mv = FromInferredType("abc") - boolval, ok = mv.GetBoolValue() + _, ok = mv.GetBoolValue() assert.False(t, ok) mv = FromDeferredType("abc") - boolval, ok = mv.GetBoolValue() + _, ok = mv.GetBoolValue() assert.False(t, ok) mv = FromInferredType("true") - boolval, ok = mv.GetBoolValue() + boolval, ok := mv.GetBoolValue() assert.True(t, boolval) assert.True(t, ok) mv = FromDeferredType("false") - boolval, ok = mv.GetBoolValue() + _, ok = mv.GetBoolValue() assert.False(t, ok, "from-data-file \"false\" should infer to string") } diff --git a/pkg/mlrval/mlrval_json.go b/pkg/mlrval/mlrval_json.go index a5dc213a7b..d1fb880ede 100644 --- a/pkg/mlrval/mlrval_json.go +++ b/pkg/mlrval/mlrval_json.go @@ -188,7 +188,9 @@ func MlrvalDecodeFromJSON(decoder *json.Decoder) ( ) } - mv := FromPending() + // Will be assigned as an array or a map + var mv *Mlrval + if isArray { mv = FromEmptyArray() @@ -203,7 +205,6 @@ func MlrvalDecodeFromJSON(decoder *json.Decoder) ( } mv.ArrayAppend(element) } - } else { mv = FromEmptyMap()