util.sql: Catch errors from LuaDBI connect (Fixes #568)
authorKim Alvefur <zash@zash.se>
Mon, 21 Mar 2016 08:50:52 +0000 (09:50 +0100)
committerKim Alvefur <zash@zash.se>
Mon, 21 Mar 2016 08:50:52 +0000 (09:50 +0100)
util/sql.lua

index dcf665fb0f2d01500c6ac3352f9d7e6b1c85438c..f64e8e10a141c4cc0a9583bfa0e6e0819e589a0f 100644 (file)
@@ -102,11 +102,12 @@ function engine:connect()
        local params = self.params;
        assert(params.driver, "no driver")
        log("debug", "Connecting to [%s] %s...", params.driver, params.database);
-       local dbh, err = DBI.Connect(
+       local ok, dbh, err = pcall(DBI.Connect,
                params.driver, params.database,
                params.username, params.password,
                params.host, params.port
        );
+       if not ok then return ok, dbh; end
        if not dbh then return nil, err; end
        dbh:autocommit(false); -- don't commit automatically
        self.conn = dbh;