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:
#include <string>
#include <zypp/Resolvable.h>
+#include <zypp/base/Exception.h>
#include "zypper.h"
*/
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
-
-#include "zypper.h"
-#include "zypper-sources.h"
-#include "zypper-tabulator.h"
-
#include <iostream>
#include <fstream>
#include <boost/format.hpp>
#include <zypp/parser/ParseException.h>
#include <zypp/media/MediaException.h>
+#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;
{
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() ? "* " : " " );