From f6703205e93bead9e9a2f74e43059d75c19914c0 Mon Sep 17 00:00:00 2001 From: George Alexopoulos Date: Thu, 25 Sep 2025 20:15:10 +0300 Subject: [PATCH] Ensure env is open in env.openDbi() --- src/env.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/env.cpp b/src/env.cpp index 9c5cfb87c0..ff71403bbb 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -592,6 +592,16 @@ NAN_METHOD(EnvWrap::openDbi) { const unsigned argc = 2; Local argv[argc] = { info.This(), info[0] }; + + // Ensure env has been opened. + // A hacky way to do that, it to check whether me_path has been set. + EnvWrap *ew = Nan::ObjectWrap::Unwrap(info.This()); + const char* path = nullptr; + int rc = mdb_env_get_path(ew->env, &path); + if (path == nullptr) { + return Nan::ThrowError("The environment is not open."); + } + Nan::MaybeLocal maybeInstance = Nan::NewInstance(Nan::New(*dbiCtor), argc, argv); // Check if database could be opened