Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first attempt at resolving nil dereference errors #439

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions marshal/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions schema/schemahandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"reflect"
"runtime/debug"

"github.com/xitongsys/parquet-go/common"
"github.com/xitongsys/parquet-go/parquet"
Expand Down Expand Up @@ -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")
Expand Down
10 changes: 7 additions & 3 deletions writer/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"context"
"encoding/binary"
"errors"
"fmt"
"io"
"reflect"
"runtime/debug"
"sync"

"github.com/apache/thrift/lib/go/thrift"
Expand Down Expand Up @@ -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() {
Expand All @@ -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")
Expand Down Expand Up @@ -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)
}
Comment on lines +305 to +308
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to wrap the invocation with a nil guard, and that seems to have helped.

Ran the test suite and it looks fine.

Is this correct? Am I missing something?

}
}
} else {
Expand Down