Skip to content

Commit a12017c

Browse files
committedMay 30, 2021
Provide exact error message if postgres connection string missing
1 parent d7a4479 commit a12017c

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed
 

‎src/database/database-postgresql.cpp

+16-11
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,24 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3939
#include "remoteplayer.h"
4040
#include "server/player_sao.h"
4141

42-
Database_PostgreSQL::Database_PostgreSQL(const std::string &connect_string) :
42+
Database_PostgreSQL::Database_PostgreSQL(const std::string &connect_string,
43+
const char *type) :
4344
m_connect_string(connect_string)
4445
{
4546
if (m_connect_string.empty()) {
46-
throw SettingNotFoundException(
47-
"Set pgsql_connection string in world.mt to "
47+
// Use given type to reference the exact setting in the error message
48+
std::string s = type;
49+
std::string msg =
50+
"Set pgsql" + s + "_connection string in world.mt to "
4851
"use the postgresql backend\n"
4952
"Notes:\n"
50-
"pgsql_connection has the following form: \n"
51-
"\tpgsql_connection = host=127.0.0.1 port=5432 user=mt_user "
52-
"password=mt_password dbname=minetest_world\n"
53+
"pgsql" + s + "_connection has the following form: \n"
54+
"\tpgsql" + s + "_connection = host=127.0.0.1 port=5432 "
55+
"user=mt_user password=mt_password dbname=minetest" + s + "\n"
5356
"mt_user should have CREATE TABLE, INSERT, SELECT, UPDATE and "
54-
"DELETE rights on the database.\n"
55-
"Don't create mt_user as a SUPERUSER!");
57+
"DELETE rights on the database. "
58+
"Don't create mt_user as a SUPERUSER!";
59+
throw SettingNotFoundException(msg);
5660
}
5761
}
5862

@@ -166,7 +170,7 @@ void Database_PostgreSQL::rollback()
166170
}
167171

168172
MapDatabasePostgreSQL::MapDatabasePostgreSQL(const std::string &connect_string):
169-
Database_PostgreSQL(connect_string),
173+
Database_PostgreSQL(connect_string, ""),
170174
MapDatabase()
171175
{
172176
connectToDatabase();
@@ -315,7 +319,7 @@ void MapDatabasePostgreSQL::listAllLoadableBlocks(std::vector<v3s16> &dst)
315319
* Player Database
316320
*/
317321
PlayerDatabasePostgreSQL::PlayerDatabasePostgreSQL(const std::string &connect_string):
318-
Database_PostgreSQL(connect_string),
322+
Database_PostgreSQL(connect_string, "_player"),
319323
PlayerDatabase()
320324
{
321325
connectToDatabase();
@@ -637,7 +641,8 @@ void PlayerDatabasePostgreSQL::listPlayers(std::vector<std::string> &res)
637641
}
638642

639643
AuthDatabasePostgreSQL::AuthDatabasePostgreSQL(const std::string &connect_string) :
640-
Database_PostgreSQL(connect_string), AuthDatabase()
644+
Database_PostgreSQL(connect_string, "_auth"),
645+
AuthDatabase()
641646
{
642647
connectToDatabase();
643648
}

‎src/database/database-postgresql.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Settings;
2929
class Database_PostgreSQL: public Database
3030
{
3131
public:
32-
Database_PostgreSQL(const std::string &connect_string);
32+
Database_PostgreSQL(const std::string &connect_string, const char *type);
3333
~Database_PostgreSQL();
3434

3535
void beginSave();

0 commit comments

Comments
 (0)
Please sign in to comment.