Changeset

13242:0d3881bf29a8

mod_storage_sql: Spell out missing dependencies Using util.dependencies appeared to cause problems with running tests in Busted, so this also removes that and uses pcall directly.
author Kim Alvefur <zash@zash.se>
date Sat, 22 Jul 2023 16:15:48 +0200
parents 13241:0419de4e4db1
children 13243:c5ccdfbbe9c1
files plugins/mod_storage_sql.lua
diffstat 1 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_storage_sql.lua	Sat Jul 22 15:22:54 2023 +0200
+++ b/plugins/mod_storage_sql.lua	Sat Jul 22 16:15:48 2023 +0200
@@ -1,11 +1,8 @@
 
 -- luacheck: ignore 212/self
 
-local deps = require "prosody.util.dependencies";
 local cache = require "prosody.util.cache";
 local json = require "prosody.util.json";
-local sqlite = deps.softreq "prosody.util.sqlite3";
-local dbisql = (sqlite and deps.softreq or require) "prosody.util.sql";
 local xml_parse = require "prosody.util.xml".parse;
 local uuid = require "prosody.util.uuid";
 local resolve_relative_path = require "prosody.util.paths".resolve_relative_path;
@@ -14,6 +11,22 @@
 local is_stanza = require"prosody.util.stanza".is_stanza;
 local t_concat = table.concat;
 
+local have_dbisql, dbisql = pcall(require, "prosody.util.sql");
+local have_sqlite, sqlite = pcall(require, "prosody.util.sqlite3");
+if not have_dbisql then
+	module:log("debug", "Could not load LuaDBI, error was: %s", dbisql)
+	dbisql = nil;
+end
+if not have_sqlite then
+	module:log("debug", "Could not load LuaSQLite3, error was: %s", sqlite)
+	sqlite = nil;
+end
+if not (have_dbisql or have_sqlite) then
+	module:log("error", "LuaDBI or LuaSQLite3 are required for using SQL databases but neither are installed");
+	module:log("error", "Please install at least one of LuaDBI and LuaSQLite3. See https://prosody.im/doc/depends");
+	error("No SQL library available")
+end
+
 local noop = function() end
 local unpack = table.unpack;
 local function iterator(result)