File tree Expand file tree Collapse file tree 3 files changed +22
-9
lines changed Expand file tree Collapse file tree 3 files changed +22
-9
lines changed Original file line number Diff line number Diff line change 44#ifndef LIBDNF5_BASE_ACTIVE_TRANSACTION_INFO_HPP
55#define LIBDNF5_BASE_ACTIVE_TRANSACTION_INFO_HPP
66
7+ #include " libdnf5/common/exception.hpp"
78#include " libdnf5/defs.h"
89
910#include < unistd.h>
1415
1516namespace libdnf5 ::base {
1617
18+ class LIBDNF_API ActiveTransactionInfoParseError : public libdnf5::Error {
19+ public:
20+ using libdnf5::Error::Error;
21+ const char * get_domain_name () const noexcept override { return " libdnf5::base" ; }
22+ const char * get_name () const noexcept override { return " ActiveTransactionInfoParseError" ; }
23+ };
24+
1725class LIBDNF_API ActiveTransactionInfo {
1826public:
1927 ActiveTransactionInfo ();
@@ -54,7 +62,8 @@ class LIBDNF_API ActiveTransactionInfo {
5462
5563 // / @brief Create ActiveTransactionInfo from TOML string
5664 // / @param toml_string The TOML string to parse
57- // / @return ActiveTransactionInfo object parsed from TOML, or empty object if parsing fails
65+ // / @return ActiveTransactionInfo object parsed from TOML
66+ // / @throws ActiveTransactionInfoParseError if TOML parsing fails
5867 static ActiveTransactionInfo from_toml (const std::string & toml_string);
5968
6069private:
Original file line number Diff line number Diff line change 33
44#include " libdnf5/base/active_transaction_info.hpp"
55
6+ #include " libdnf5/utils/bgettext/bgettext-mark-domain.h"
7+
68#include < toml.hpp>
79
810#include < ctime>
@@ -87,10 +89,10 @@ ActiveTransactionInfo ActiveTransactionInfo::from_toml(const std::string & toml_
8789 info.set_comment (toml::find_or<std::string>(data, " comment" , " " ));
8890 info.set_pid (toml::find_or<pid_t >(data, " pid" , -1 ));
8991 info.set_start_time (toml::find_or<time_t >(data, " start_time" , 0 ));
90- } catch (const toml::syntax_error &) {
91- // Return default/empty ActiveTransactionInfo on TOML syntax errors
92- } catch (const toml::type_error &) {
93- // Return default/empty ActiveTransactionInfo on TOML type errors
92+ } catch (const toml::syntax_error & ex ) {
93+ throw ActiveTransactionInfoParseError ( M_ ( " Error parsing transaction info: {} " ), std::string (ex. what ()));
94+ } catch (const toml::type_error & ex ) {
95+ throw ActiveTransactionInfoParseError ( M_ ( " Error parsing transaction info: {} " ), std::string (ex. what ()));
9496 }
9597
9698 return info;
Original file line number Diff line number Diff line change @@ -986,10 +986,15 @@ Transaction::TransactionRunResult Transaction::Impl::_run(
986986 lock_file_path /= std::filesystem::path (libdnf5::TRANSACTION_LOCK_FILEPATH).relative_path ();
987987 std::filesystem::create_directories (lock_file_path.parent_path ());
988988
989+ auto logger = base->get_logger ().get ();
989990 TransactionLocker transaction_locker (lock_file_path, info);
990991 if (!transaction_locker.write_lock ()) {
991992 auto content = transaction_locker.read_content ();
992- concurrent_transaction = std::make_unique<ActiveTransactionInfo>(ActiveTransactionInfo::from_toml (content));
993+ try {
994+ concurrent_transaction = std::make_unique<ActiveTransactionInfo>(ActiveTransactionInfo::from_toml (content));
995+ } catch (const ActiveTransactionInfoParseError & ex) {
996+ logger->warning (ex.what ());
997+ }
993998 return TransactionRunResult::ERROR_LOCK;
994999 }
9951000 transaction_locker.write_transaction_metadata ();
@@ -1105,9 +1110,6 @@ Transaction::TransactionRunResult Transaction::Impl::_run(
11051110 db_transaction.set_dt_start (std::chrono::duration_cast<std::chrono::seconds>(time).count ());
11061111 db_transaction.start ();
11071112
1108-
1109- auto logger = base->get_logger ().get ();
1110-
11111113 int pipe_out_from_scriptlets[2 ];
11121114 if (pipe2 (pipe_out_from_scriptlets, O_CLOEXEC) == -1 ) {
11131115 logger->error (" Transaction::Run: Cannot create pipe: {}" , std::strerror (errno));
You can’t perform that action at this time.
0 commit comments