From 5f74d27a1b816f8c28105c910526c1a94404a2e3 Mon Sep 17 00:00:00 2001 From: Shlomi Vaknin Date: Sun, 9 Jan 2022 14:37:02 -0800 Subject: [PATCH] first attempt at resolving nil dereference errors --- marshal/marshal.go | 8 +++++--- schema/schemahandler.go | 2 ++ writer/writer.go | 10 +++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/marshal/marshal.go b/marshal/marshal.go index 443f20f5..c81246e7 100644 --- a/marshal/marshal.go +++ b/marshal/marshal.go @@ -2,14 +2,15 @@ package marshal import ( "errors" - "reflect" - "strings" - + "fmt" "github.com/xitongsys/parquet-go/common" "github.com/xitongsys/parquet-go/layout" "github.com/xitongsys/parquet-go/parquet" "github.com/xitongsys/parquet-go/schema" "github.com/xitongsys/parquet-go/types" + "reflect" + "runtime/debug" + "strings" ) type Node struct { @@ -237,6 +238,7 @@ func Marshal(srcInterface []interface{}, schemaHandler *schema.SchemaHandler) (t case string: err = errors.New(x) case error: + fmt.Printf("RECOVER PANIC FROM PARQUET-GO: %s: %s", x, debug.Stack()) err = x default: err = errors.New("unkown error") diff --git a/schema/schemahandler.go b/schema/schemahandler.go index 75345b1b..087f1f6d 100644 --- a/schema/schemahandler.go +++ b/schema/schemahandler.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "reflect" + "runtime/debug" "github.com/xitongsys/parquet-go/common" "github.com/xitongsys/parquet-go/parquet" @@ -234,6 +235,7 @@ func NewSchemaHandlerFromStruct(obj interface{}) (sh *SchemaHandler, err error) case string: err = errors.New(x) case error: + fmt.Printf("RECOVER PANIC FROM PARQUET-GO: %s: %s", x, debug.Stack()) err = x default: err = errors.New("error occurred") diff --git a/writer/writer.go b/writer/writer.go index 18d1d6aa..af51b93c 100644 --- a/writer/writer.go +++ b/writer/writer.go @@ -4,8 +4,10 @@ import ( "context" "encoding/binary" "errors" + "fmt" "io" "reflect" + "runtime/debug" "sync" "github.com/apache/thrift/lib/go/thrift" @@ -259,7 +261,6 @@ func (pw *ParquetWriter) flushObjs() error { if bgn >= l { bgn, end = l, l } - wg.Add(1) go func(b, e int, index int64) { defer func() { @@ -269,6 +270,7 @@ func (pw *ParquetWriter) flushObjs() error { case string: errs[index] = errors.New(x) case error: + fmt.Printf("RECOVER PANIC FROM PARQUET-GO: %s: %s", x, debug.Stack()) errs[index] = x default: errs[index] = errors.New("unknown error") @@ -300,8 +302,10 @@ func (pw *ParquetWriter) flushObjs() error { }() } else { - pagesMapList[index][name], _ = layout.TableToDataPages(table, int32(pw.PageSize), - pw.CompressionType) + if table.Schema.Type != nil { + pagesMapList[index][name], _ = layout.TableToDataPages(table, int32(pw.PageSize), + pw.CompressionType) + } } } } else {