Skip to content

Commit

Permalink
NewContext should use tiledb_ctx_alloc_with_error
Browse files Browse the repository at this point in the history
This allows capturing any errors on alloc of the context.
  • Loading branch information
Shelnutt2 committed Jun 1, 2022
1 parent a1ad55b commit 5eee8cd
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package tiledb
#cgo LDFLAGS: -ltiledb
#cgo linux LDFLAGS: -ldl
#include <tiledb/tiledb.h>
#include <tiledb/tiledb_experimental.h>
#include <stdlib.h>
*/
import "C"
Expand All @@ -28,13 +29,25 @@ type Context struct {
func NewContext(config *Config) (*Context, error) {
var context Context
var ret C.int32_t
var err *C.tiledb_error_t
if config != nil {
ret = C.tiledb_ctx_alloc(config.tiledbConfig, &context.tiledbContext)
ret = C.tiledb_ctx_alloc_with_error(config.tiledbConfig, &context.tiledbContext, &err)
} else {
ret = C.tiledb_ctx_alloc(nil, &context.tiledbContext)
ret = C.tiledb_ctx_alloc_with_error(nil, &context.tiledbContext, &err)
}
if ret != C.TILEDB_OK {
return nil, fmt.Errorf("error creating tiledb context: %w", context.LastError())
// If the error isn't null report this
if err != nil {
var msg *C.char
C.tiledb_error_message(err, &msg)
defer C.tiledb_error_free(&err)
return nil, fmt.Errorf("error creating tiledb context: %s", C.GoString(msg))
}
// If the context is not null see if the error exists there
if context.tiledbContext != nil {
return nil, fmt.Errorf("error creating tiledb context: %w", context.LastError())
}
return nil, fmt.Errorf("error creating tiledb context: unknown error")
}

// Set finalizer for free C pointer on gc
Expand Down

0 comments on commit 5eee8cd

Please sign in to comment.