mod_storage_sql: Display friendlier error when LuaDBI is missing
authorMatthew Wild <mwild1@gmail.com>
Tue, 1 Mar 2011 06:12:43 +0000 (06:12 +0000)
committerMatthew Wild <mwild1@gmail.com>
Tue, 1 Mar 2011 06:12:43 +0000 (06:12 +0000)
plugins/mod_storage_sql.lua

index 7917958d385245346ad28e702cf387d89b8f4f90..b88efb6423b31ee274ab35efc09d4de4b72d9ac8 100644 (file)
@@ -96,7 +96,18 @@ local function create_table()
 end
 
 do -- process options to get a db connection
-       DBI = require "DBI";
+       local ok;
+       prosody.unlock_globals();
+       ok, DBI = pcall(require, "DBI");
+       if not ok then
+               package.loaded["DBI"] = {};
+               module:log("error", "Failed to load the LuaDBI library for accessing SQL databases: %s", DBI);
+               module:log("error", "More information on installing LuaDBI can be found at http://prosody.im/doc/depends#luadbi");
+       end
+       prosody.lock_globals();
+       if not ok or not DBI.Connect then
+               return; -- Halt loading of this module
+       end
 
        params = params or { driver = "SQLite3" };