Skip to content

Commit

Permalink
Merge pull request #223 from TileDB-Inc/sethshelnutt/sc-18266/use-til…
Browse files Browse the repository at this point in the history
…edb-ctx-alloc-with-error-to-capture

NewContext should use tiledb_ctx_alloc_with_error
  • Loading branch information
teo-tsirpanis authored Feb 17, 2025
2 parents a3a0a4c + 50d8656 commit 1baa6d2
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 @@ -2,6 +2,7 @@ package tiledb

/*
#include <tiledb/tiledb.h>
#include <tiledb/tiledb_experimental.h>
#include <stdlib.h>
*/
import "C"
Expand All @@ -26,13 +27,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")
}
freeOnGC(&context)

Expand Down

0 comments on commit 1baa6d2

Please sign in to comment.