From 91c3833c7cab7f29e1b2f756311500b27e5f7510 Mon Sep 17 00:00:00 2001 From: adjoly Date: Wed, 23 Apr 2025 17:42:32 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20fixed?= =?UTF-8?q?=20issue=20with=20tomlpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exemples/test.toml | 10 +++++----- src/config/Config.cpp | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/exemples/test.toml b/exemples/test.toml index 60416b7..a339c95 100644 --- a/exemples/test.toml +++ b/exemples/test.toml @@ -25,15 +25,15 @@ cgi.go = "/bin/go" [server.location./redir] redirect = "https://kanel.ovh" -[server1] +[server3] server_names = { "ptnnnn.local"} -host = "0.0.0.0" -port = 90 +host = "127.0.0.2" +port = 9090 -[server1.error_pages] +[serverr.error_pages] 404 = "existepasfd***.html" -[server1.location./] +[serverr.location./] methods = { "GET", "DELETE" } root = "/var/lib/docker/volumes/test_data/_data" dirlist = false diff --git a/src/config/Config.cpp b/src/config/Config.cpp index 02513d1..eb34fda 100644 --- a/src/config/Config.cpp +++ b/src/config/Config.cpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/14 12:53:54 by adjoly #+# #+# */ -/* Updated: 2025/04/22 15:35:52 by adjoly ### ########.fr */ +/* Updated: 2025/04/23 17:42:07 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,13 +15,19 @@ #include "cppeleven.hpp" #include "node/ANode.hpp" #include +#include using namespace webserv::config; Config::Config(std::string &filename) { toml::Toml *file = new toml::Toml(filename); - file->parse(); + try { + file->parse(); + } catch (std::runtime_error &e) { + delete file; + throw e; + } toml::ANode *table = file->getParsedFile(); bool found = false; @@ -36,8 +42,13 @@ Config::Config(std::string &filename) { for (auto it = prange(node)) { if (it->second->type() == toml::TABLE) { _log->info("taking server from table : " + it->first); - Server *srv = new Server(it->second); - _servers.push_back(srv); + try { + Server *srv = new Server(it->second); + _servers.push_back(srv); + } catch (std::runtime_error &e) { + _log->error(e.what()); + break; + } } } delete table;