juk3n/fluffypublic Fork
⑂ 33742aa
Commits
⬇ Clone ▾
git clone https://git.rickub.com/juk3n/fluffy.git
git clone ssh://git@rickub.com/juk3n/fluffy.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

added printing debug error messages

juk3n committed 2024-07-08T12:18:34+02:00 Browse files
33742aa parent: 190870d
modified app/include/database.hpp +8 -7
@@ -4,10 +4,12 @@
44 #include <string>
55
66 #include <game.hpp>
7+#include <output.hpp>
78
89 class Database
910 {
1011 private:
12+ Output output{};
1113 sqlite3 *database;
1214
1315 std::string database_initialization_command =
@@ -19,7 +21,7 @@ private:
1921
2022 auto initializeDatabase() -> void {
2123 executeSqlCommand(database_initialization_command);
22- //printMessage("Database Initialized");
24+ output.printDebugMessage("Database Initialized");
2325 }
2426
2527 public:
@@ -38,7 +40,8 @@ public:
3840 exit = sqlite3_exec(database, command.c_str(), nullptr, nullptr, &messageError);
3941
4042 if (exit != SQLITE_OK) {
41- //printMessage("Error with command: " + command + " " + messageError);
43+
44+ output.printDebugMessage("Error with command: " + command + " " + messageError);
4245 sqlite3_free(messageError);
4346 throw std::exception();
4447 }
@@ -53,12 +56,11 @@ public:
5356 exit = sqlite3_open(databasePath.c_str(), &database);
5457
5558 if (exit) {
56- std::cerr << "Error opening database" << sqlite3_errmsg(database)
57- << std::endl;
59+ output.printDebugError("Error opening database" + std::string{sqlite3_errmsg(database)});
5860 throw std::exception();
5961 }
6062
61- //printMessage("Opened database successfully!");
63+ output.printDebugMessage("Opened database successfully!");
6264
6365 if (newCreation) {
6466 initializeDatabase();
@@ -71,8 +73,7 @@ public:
7173 exit = sqlite3_prepare_v2(database, select_all_games_command.c_str(), -1, &stmt, nullptr);
7274
7375 if (exit) {
74- std::cerr << "Error retrieving data" << sqlite3_errmsg(database)
75- << std::endl;
76+ output.printDebugError("Error retrieving data" + std::string{sqlite3_errmsg(database)});
7677 sqlite3_close(database);
7778 return {};
7879 }
@@ -4,10 +4,12 @@
4 #include <string>4 #include <string>
5 5
6 #include <game.hpp>6 #include <game.hpp>
7+#include <output.hpp>
7 8
8 class Database9 class Database
9 {10 {
10 private:11 private:
12+ Output output{};
11 sqlite3 *database;13 sqlite3 *database;
12 14
13 std::string database_initialization_command =15 std::string database_initialization_command =
@@ -19,7 +21,7 @@ private:
19 21
20 auto initializeDatabase() -> void {22 auto initializeDatabase() -> void {
21 executeSqlCommand(database_initialization_command);23 executeSqlCommand(database_initialization_command);
22- //printMessage("Database Initialized");24+ output.printDebugMessage("Database Initialized");
23 }25 }
24 26
25 public:27 public:
@@ -38,7 +40,8 @@ public:
38 exit = sqlite3_exec(database, command.c_str(), nullptr, nullptr, &messageError);40 exit = sqlite3_exec(database, command.c_str(), nullptr, nullptr, &messageError);
39 41
40 if (exit != SQLITE_OK) {42 if (exit != SQLITE_OK) {
41- //printMessage("Error with command: " + command + " " + messageError);43+
44+ output.printDebugMessage("Error with command: " + command + " " + messageError);
42 sqlite3_free(messageError);45 sqlite3_free(messageError);
43 throw std::exception();46 throw std::exception();
44 }47 }
@@ -53,12 +56,11 @@ public:
53 exit = sqlite3_open(databasePath.c_str(), &database);56 exit = sqlite3_open(databasePath.c_str(), &database);
54 57
55 if (exit) {58 if (exit) {
56- std::cerr << "Error opening database" << sqlite3_errmsg(database)59+ output.printDebugError("Error opening database" + std::string{sqlite3_errmsg(database)});
57- << std::endl;
58 throw std::exception();60 throw std::exception();
59 }61 }
60 62
61- //printMessage("Opened database successfully!");63+ output.printDebugMessage("Opened database successfully!");
62 64
63 if (newCreation) {65 if (newCreation) {
64 initializeDatabase();66 initializeDatabase();
@@ -71,8 +73,7 @@ public:
71 exit = sqlite3_prepare_v2(database, select_all_games_command.c_str(), -1, &stmt, nullptr);73 exit = sqlite3_prepare_v2(database, select_all_games_command.c_str(), -1, &stmt, nullptr);
72 74
73 if (exit) {75 if (exit) {
74- std::cerr << "Error retrieving data" << sqlite3_errmsg(database)76+ output.printDebugError("Error retrieving data" + std::string{sqlite3_errmsg(database)});
75- << std::endl;
76 sqlite3_close(database);77 sqlite3_close(database);
77 return {};78 return {};
78 }79 }
modified app/include/output.hpp +8 -1
@@ -4,8 +4,15 @@
44 #include <string>
55
66 class Output {
7+private:
8+ bool debugRun = false;
79 public:
810 auto printDebugMessage(std::string message) -> void {
9- std::cout << message << std::endl;
11+ if (debugRun)
12+ std::cout << message << std::endl;
13+ }
14+ auto printDebugError(std::string message) -> void {
15+ if (debugRun)
16+ std::cerr << message << std::endl;
1017 }
1118 };
\ No newline at end of file
@@ -4,8 +4,15 @@
4 #include <string>4 #include <string>
5 5
6 class Output {6 class Output {
7+private:
8+ bool debugRun = false;
7 public:9 public:
8 auto printDebugMessage(std::string message) -> void {10 auto printDebugMessage(std::string message) -> void {
9- std::cout << message << std::endl;11+ if (debugRun)
12+ std::cout << message << std::endl;
13+ }
14+ auto printDebugError(std::string message) -> void {
15+ if (debugRun)
16+ std::cerr << message << std::endl;
10 }17 }
11 };18 };
\ No newline at end of file\ No newline at end of file