From d40173ce432bcc7cf99bd8e13061be01be940a50 Mon Sep 17 00:00:00 2001 From: Jan Kupec Date: Thu, 9 Aug 2007 12:40:44 +0000 Subject: [PATCH] - addrepo error reporting improved --- src/zypper-callbacks.cc | 33 +++++++++++++++++++++++++++++++++ src/zypper-callbacks.h | 25 +++++++++++++++++++++++++ src/zypper-sources.cc | 44 ++++++++++++++++++++++---------------------- 3 files changed, 80 insertions(+), 22 deletions(-) diff --git a/src/zypper-callbacks.cc b/src/zypper-callbacks.cc index 7f84607..c609d90 100644 --- a/src/zypper-callbacks.cc +++ b/src/zypper-callbacks.cc @@ -188,6 +188,39 @@ string to_string (zypp::Resolvable::constPtr resolvable) { return ss.str (); } +// ---------------------------------------------------------------------------- + +void report_zypp_exception(const zypp::Exception & e) +{ + if (e.historySize()) + { + if (gSettings.verbosity > 2) + // print the whole history + cerr << e.historyAsString(); + else + // print the root cause + cerr << *e.historyEnd(); + } + else + cerr << e.asUserString(); + cerr << endl; +} + +void report_problem(const zypp::Exception & e, + const string & problem_desc, + const string & hint) +{ + // problem + cerr << problem_desc << endl; + + // cause + report_zypp_exception(e); + + // hint + if (!hint.empty()) + cerr << hint << endl; +} + // Local Variables: // c-basic-offset: 2 // End: diff --git a/src/zypper-callbacks.h b/src/zypper-callbacks.h index 396a9ad..a521103 100644 --- a/src/zypper-callbacks.h +++ b/src/zypper-callbacks.h @@ -14,6 +14,7 @@ #include #include +#include #include "zypper.h" @@ -64,5 +65,29 @@ int read_action_ari (int default_action = -1); */ bool read_bool_answer(const string & question, bool default_answer); +/** + * Returns string representation of a resolvable. + */ std::string to_string (zypp::Resolvable::constPtr resolvable); + +/** + * Prints exception message. If there is exception history available for the + * exception, this method prints the root cause or the whole history (if + * verbosity level is >2). Otherwise it just prist the e.asUserString() of the + * exception passed. + */ +void report_zypp_exception(const zypp::Exception & e); + +/** + * Prints the problem description caused by an exception, its cause and, + * optionaly, a hint for the user. + * + * \param e Exception which caused the problem. + * \param Problem description for the user. + * \param Hint for the user how to cope with the problem. + */ +void report_problem(const zypp::Exception & e, + const string & problem_desc, + const string & hint = ""); + #endif diff --git a/src/zypper-sources.cc b/src/zypper-sources.cc index 63bad0c..83e4487 100644 --- a/src/zypper-sources.cc +++ b/src/zypper-sources.cc @@ -1,8 +1,3 @@ - -#include "zypper.h" -#include "zypper-sources.h" -#include "zypper-tabulator.h" - #include #include #include @@ -18,6 +13,11 @@ #include #include +#include "zypper.h" +#include "zypper-tabulator.h" +#include "zypper-callbacks.h" +#include "zypper-sources.h" + using namespace std; using namespace zypp; using namespace zypp::repo; @@ -432,42 +432,42 @@ int add_repo(const RepoInfo & repo) { manager.addRepository(repo); } - catch (const MediaException & e) - { - cerr << _("Problem transfering repository data from specified URL.") << endl; - ERR << "Problem transfering repository data from specified URL." << endl; - return ZYPPER_EXIT_ERR_ZYPP; - } - catch (const ParseException & e) - { - cerr << _("Problem parsing repository data.") << endl; - ERR << "Problem parsing repository data." << endl; - return ZYPPER_EXIT_ERR_ZYPP; - } catch (const RepoAlreadyExistsException & e) { - cerr << format("Repository named '%s' already exists.") % repo.alias() << endl; + ZYPP_CAUGHT(e); + cerr << format(_("Repository named '%s' already exists. Please, use another alias.")) + % repo.alias() << endl; ERR << "Repository named '%s' already exists." << endl; return ZYPPER_EXIT_ERR_ZYPP; } catch (const RepoUnknownTypeException & e) { - cerr << format(_("Can't find a valid repository at given location")) << endl; - ERR << "Problem parsing repository data." << endl; + ZYPP_CAUGHT(e); + cerr << _("Can't find a valid repository at given location:") << endl; + cerr << _("Could not determine the type of the repository." + " Please, check if the defined URLs (see below) point to a valid repository:"); + for(RepoInfo::urls_const_iterator uit = repo.baseUrlsBegin(); + uit != repo.baseUrlsEnd(); ++uit) + cerr << (*uit) << endl; return ZYPPER_EXIT_ERR_ZYPP; } catch (const RepoException & e) { - cerr << e.msg() << endl; + ZYPP_CAUGHT(e); + report_problem(e, + _("Problem transfering repository data from specified URL:"), + _("Please, check whether the specified URL is accessible.")); + ERR << "Problem transfering repository data from specified URL" << endl; return ZYPPER_EXIT_ERR_ZYPP; } catch (const Exception & e) { ZYPP_CAUGHT(e); - cerr << e.asUserString() << endl; + report_problem(e, _("Unknown problem when adding repository:")); return ZYPPER_EXIT_ERR_BUG; } + //! \todo different output for -r and for zypper. cout_n << format(_("Repository '%s' successfully added:")) % repo.alias() << endl; cout_n << ( repo.enabled() ? "[x]" : "[ ]" ); cout_n << ( repo.autorefresh() ? "* " : " " ); -- 2.7.4