From 2e8e6023cbc5af0ba2c9aaad6cd17cec2fa30a5a Mon Sep 17 00:00:00 2001 From: Hang Xie <7977860+hangxie@users.noreply.github.com> Date: Sun, 17 Apr 2022 07:46:14 -0700 Subject: [PATCH] avoid java/c++ style of try-catch --- layout/rowgroup.go | 16 +--------------- marshal/json.go | 14 -------------- marshal/marshal.go | 14 -------------- marshal/unmarshal.go | 14 -------------- schema/json.go | 14 -------------- schema/schemahandler.go | 13 ------------- 6 files changed, 1 insertion(+), 84 deletions(-) diff --git a/layout/rowgroup.go b/layout/rowgroup.go index 3d12a734..6756b7b9 100644 --- a/layout/rowgroup.go +++ b/layout/rowgroup.go @@ -1,7 +1,6 @@ package layout import ( - "errors" "sync" "github.com/xitongsys/parquet-go/common" @@ -68,20 +67,7 @@ func ReadRowGroup(rowGroupHeader *parquet.RowGroup, PFile source.ParquetFile, sc wg.Add(1) go func(index int64, bgn int64, end int64) { - defer func() { - wg.Done() - if r := recover(); r != nil { - switch x := r.(type) { - case string: - err = errors.New(x) - case error: - err = x - default: - err = errors.New("unknown error") - } - } - }() - + defer wg.Done() for i := bgn; i < end; i++ { offset := columnChunks[i].FileOffset PFile := PFile diff --git a/marshal/json.go b/marshal/json.go index 410a5640..026d6281 100644 --- a/marshal/json.go +++ b/marshal/json.go @@ -3,7 +3,6 @@ package marshal import ( "bytes" "encoding/json" - "errors" "reflect" "strings" @@ -16,19 +15,6 @@ import ( //ss is []string func MarshalJSON(ss []interface{}, schemaHandler *schema.SchemaHandler) (tb *map[string]*layout.Table, err error) { - defer func() { - if r := recover(); r != nil { - switch x := r.(type) { - case string: - err = errors.New(x) - case error: - err = x - default: - err = errors.New("unknown error") - } - } - }() - res := make(map[string]*layout.Table) pathMap := schemaHandler.PathMap nodeBuf := NewNodeBuf(1) diff --git a/marshal/marshal.go b/marshal/marshal.go index 443f20f5..457e16f4 100644 --- a/marshal/marshal.go +++ b/marshal/marshal.go @@ -1,7 +1,6 @@ package marshal import ( - "errors" "reflect" "strings" @@ -231,19 +230,6 @@ func (p *ParquetMap) Marshal(node *Node, nodeBuf *NodeBufType) []*Node { //Convert the objects to table map. srcInterface is a slice of objects func Marshal(srcInterface []interface{}, schemaHandler *schema.SchemaHandler) (tb *map[string]*layout.Table, err error) { - defer func() { - if r := recover(); r != nil { - switch x := r.(type) { - case string: - err = errors.New(x) - case error: - err = x - default: - err = errors.New("unkown error") - } - } - }() - src := reflect.ValueOf(srcInterface) res := make(map[string]*layout.Table) pathMap := schemaHandler.PathMap diff --git a/marshal/unmarshal.go b/marshal/unmarshal.go index 85820044..98fb07b1 100644 --- a/marshal/unmarshal.go +++ b/marshal/unmarshal.go @@ -1,7 +1,6 @@ package marshal import ( - "errors" "reflect" "strings" @@ -29,19 +28,6 @@ type SliceRecord struct { //Convert the table map to objects slice. dstInterface is a slice of pointers of objects func Unmarshal(tableMap *map[string]*layout.Table, bgn int, end int, dstInterface interface{}, schemaHandler *schema.SchemaHandler, prefixPath string) (err error) { - defer func() { - if r := recover(); r != nil { - switch x := r.(type) { - case string: - err = errors.New(x) - case error: - err = x - default: - err = errors.New("unknown error") - } - } - }() - tableNeeds := make(map[string]*layout.Table) tableBgn, tableEnd := make(map[string]int), make(map[string]int) for name, table := range *tableMap { diff --git a/schema/json.go b/schema/json.go index dad372bc..a6d66368 100644 --- a/schema/json.go +++ b/schema/json.go @@ -2,7 +2,6 @@ package schema import ( "encoding/json" - "errors" "fmt" "github.com/xitongsys/parquet-go/common" @@ -19,19 +18,6 @@ func NewJSONSchemaItem() *JSONSchemaItemType { } func NewSchemaHandlerFromJSON(str string) (sh *SchemaHandler, err error) { - defer func() { - if r := recover(); r != nil { - switch x := r.(type) { - case string: - err = errors.New(x) - case error: - err = x - default: - err = errors.New("unknown error") - } - } - }() - schema := NewJSONSchemaItem() if err := json.Unmarshal([]byte(str), schema); err != nil { return nil, fmt.Errorf("error in unmarshalling json schema string: %v", err.Error()) diff --git a/schema/schemahandler.go b/schema/schemahandler.go index 75345b1b..fd1271a1 100644 --- a/schema/schemahandler.go +++ b/schema/schemahandler.go @@ -228,19 +228,6 @@ func NewItem() *Item { //Create schema handler from a object func NewSchemaHandlerFromStruct(obj interface{}) (sh *SchemaHandler, err error) { - defer func() { - if r := recover(); r != nil { - switch x := r.(type) { - case string: - err = errors.New(x) - case error: - err = x - default: - err = errors.New("error occurred") - } - } - }() - ot := reflect.TypeOf(obj).Elem() item := NewItem() item.GoType = ot