diff --git a/context.go b/context.go index 184e8b5b..a0dc0fca 100644 --- a/context.go +++ b/context.go @@ -4,6 +4,7 @@ package tiledb #cgo LDFLAGS: -ltiledb #cgo linux LDFLAGS: -ldl #include +#include #include */ import "C" @@ -28,13 +29,25 @@ type Context struct { func NewContext(config *Config) (*Context, error) { var context Context var ret C.int32_t + var tdbErr *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, &tdbErr) } else { - ret = C.tiledb_ctx_alloc(nil, &context.tiledbContext) + ret = C.tiledb_ctx_alloc_with_error(nil, &context.tiledbContext, &tdbErr) } 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 tdbErr != nil { + var msg *C.char + C.tiledb_error_message(tdbErr, &msg) + defer C.tiledb_error_free(&tdbErr) + 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