diff --git a/doc/lua_api.md b/doc/lua_api.md index 4d461f335..27a9fef96 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -8669,7 +8669,7 @@ In multiplayer mode, the error may be arbitrarily large. Interface for the operating system's crypto-secure PRNG. -It can be created via `SecureRandom()`. The constructor returns nil if a +It can be created via `SecureRandom()`. The constructor throws an error if a secure random device cannot be found on the system. ### Methods diff --git a/src/script/lua_api/l_noise.cpp b/src/script/lua_api/l_noise.cpp index 9836f4b09..ead14fec0 100644 --- a/src/script/lua_api/l_noise.cpp +++ b/src/script/lua_api/l_noise.cpp @@ -641,10 +641,9 @@ int LuaSecureRandom::create_object(lua_State *L) { LuaSecureRandom *o = new LuaSecureRandom(); - // Fail and return nil if we can't securely fill the buffer if (!o->fillRandBuf()) { delete o; - return 0; + throw LuaError("SecureRandom: Failed to find secure random device on system"); } *(void **)(lua_newuserdata(L, sizeof(void *))) = o;