From c1b7f214fd5286151bec1abe493950aef053e320 Mon Sep 17 00:00:00 2001 From: Arvin Schnell Date: Wed, 12 Jul 2023 09:27:12 +0200 Subject: [PATCH] - improved error message --- LIBVERSION | 2 +- client/errors.cc | 6 +++--- client/snapper.cc | 4 ++-- server/Client.cc | 4 ++-- snapper/Exception.h | 12 ++++++++---- snapper/Snapper.cc | 12 ++++++------ 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/LIBVERSION b/LIBVERSION index 9fe9ff9d..a3fcc712 100644 --- a/LIBVERSION +++ b/LIBVERSION @@ -1 +1 @@ -7.0.1 +7.1.0 diff --git a/client/errors.cc b/client/errors.cc index a38b85d0..bda684e3 100644 --- a/client/errors.cc +++ b/client/errors.cc @@ -1,6 +1,6 @@ /* * Copyright (c) [2011-2014] Novell, Inc. - * Copyright (c) [2016-2021] SUSE LLC + * Copyright (c) [2016-2023] SUSE LLC * * All Rights Reserved. * @@ -102,10 +102,10 @@ error_description(const DBus::ErrorException& e) return _("Deleting snapshot failed."); if (name == "error.invalid_user") - return _("Invalid user."); + return sformat(_("Invalid user (%s)."), e.message()); if (name == "error.invalid_group") - return _("Invalid group."); + return sformat(_("Invalid group (%s)."), e.message()); if (name == "error.acl_error") return _("ACL error."); diff --git a/client/snapper.cc b/client/snapper.cc index 0381ac03..3ddebe1e 100644 --- a/client/snapper.cc +++ b/client/snapper.cc @@ -298,13 +298,13 @@ main(int argc, char** argv) catch (const InvalidUserException& e) { SN_CAUGHT(e); - cerr << _("Invalid user.") << endl; + cerr << sformat(_("Invalid user (%s)."), e.what()) << endl; exit(EXIT_FAILURE); } catch (const InvalidGroupException& e) { SN_CAUGHT(e); - cerr << _("Invalid group.") << endl; + cerr << sformat(_("Invalid group (%s)."), e.what()) << endl; exit(EXIT_FAILURE); } catch (const QuotaException& e) diff --git a/server/Client.cc b/server/Client.cc index b71c1cbe..c117c035 100644 --- a/server/Client.cc +++ b/server/Client.cc @@ -1987,13 +1987,13 @@ Client::dispatch(DBus::Connection& conn, DBus::Message& msg) catch (const InvalidUserException& e) { SN_CAUGHT(e); - DBus::MessageError reply(msg, "error.invalid_user", DBUS_ERROR_FAILED); + DBus::MessageError reply(msg, "error.invalid_user", e.what()); conn.send(reply); } catch (const InvalidGroupException& e) { SN_CAUGHT(e); - DBus::MessageError reply(msg, "error.invalid_group", DBUS_ERROR_FAILED); + DBus::MessageError reply(msg, "error.invalid_group", e.what()); conn.send(reply); } catch (const QuotaException& e) diff --git a/snapper/Exception.h b/snapper/Exception.h index a9be4192..04f1c438 100644 --- a/snapper/Exception.h +++ b/snapper/Exception.h @@ -1,6 +1,6 @@ /* * Copyright (c) [2011-2014] Novell, Inc. - * Copyright (c) [2015,2018] SUSE LLC + * Copyright (c) [2015-2023] SUSE LLC * * All Rights Reserved. * @@ -386,17 +386,21 @@ namespace snapper struct InvalidUserException : public Exception { - explicit InvalidUserException() : Exception("invalid user") {} + explicit InvalidUserException() __attribute__((deprecated)) : Exception("invalid user") {} + explicit InvalidUserException(const std::string& user) : Exception("invalid user '" + user + "'") {} + // TODO save user }; struct InvalidGroupException : public Exception { - explicit InvalidGroupException() : Exception("invalid group") {} + explicit InvalidGroupException() __attribute__((deprecated)) : Exception("invalid group") {} + explicit InvalidGroupException(const std::string& group) : Exception("invalid group '" + group + "'") {} + // TODO save group }; struct UnsupportedException : public Exception { - explicit UnsupportedException() : Exception("unsupported") {} + explicit UnsupportedException() : Exception("unsupported") {} }; } diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index 85ba0966..7d20068b 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -554,11 +554,11 @@ namespace snapper vector users; if (config_info->get_value(KEY_ALLOW_USERS, users)) { - for (vector::const_iterator it = users.begin(); it != users.end(); ++it) + for (const string& user : users) { uid_t uid; - if (!get_user_uid(it->c_str(), uid)) - SN_THROW(InvalidUserException()); + if (!get_user_uid(user.c_str(), uid)) + SN_THROW(InvalidUserException(user)); uids.push_back(uid); } } @@ -567,11 +567,11 @@ namespace snapper vector groups; if (config_info->get_value(KEY_ALLOW_GROUPS, groups)) { - for (vector::const_iterator it = groups.begin(); it != groups.end(); ++it) + for (const string& group : groups) { gid_t gid; - if (!get_group_gid(it->c_str(), gid)) - SN_THROW(InvalidGroupException()); + if (!get_group_gid(group.c_str(), gid)) + SN_THROW(InvalidGroupException(group)); gids.push_back(gid); } } -- 2.47.3