From c3cea0d713925fbd4dda33089ba3da11c4bd1c8e Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Wed, 28 May 2014 13:41:06 +0200 Subject: [PATCH] Fix service methods to throw ServiceException, not RepoException. --- zypp/RepoManager.cc | 9 ++++----- zypp/repo/RepoException.cc | 22 ++++++++++++++++------ zypp/repo/RepoException.h | 29 ++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/zypp/RepoManager.cc b/zypp/RepoManager.cc index 523fe90..e673038 100644 --- a/zypp/RepoManager.cc +++ b/zypp/RepoManager.cc @@ -1724,7 +1724,7 @@ namespace zypp Pathname location = service.filepath(); if( location.empty() ) { - ZYPP_THROW(RepoException( _("Can't figure out where the service is stored.") )); + ZYPP_THROW(ServiceException( _("Can't figure out where the service is stored.") )); } ServiceSet tmpSet; @@ -1736,7 +1736,7 @@ namespace zypp if ( filesystem::unlink(location) != 0 ) { // TranslatorExplanation '%s' is a filename - ZYPP_THROW(RepoException(str::form( _("Can't delete '%s'"), location.c_str() ))); + ZYPP_THROW(ServiceException(str::form( _("Can't delete '%s'"), location.c_str() ))); } MIL << alias << " sucessfully deleted." << endl; } @@ -2067,8 +2067,7 @@ namespace zypp if ( service.type() == ServiceType::PLUGIN ) { - WAR << "Not modifying plugin service '" << oldAlias << "'" << endl; - return; + ZYPP_THROW(ServicePluginImmutableException()); } const ServiceInfo & oldService = getService(oldAlias); @@ -2076,7 +2075,7 @@ namespace zypp Pathname location = oldService.filepath(); if( location.empty() ) { - ZYPP_THROW(RepoException( _("Can't figure out where the service is stored.") )); + ZYPP_THROW(ServiceException( _("Can't figure out where the service is stored.") )); } // remember: there may multiple services being defined in one file: diff --git a/zypp/repo/RepoException.cc b/zypp/repo/RepoException.cc index cb25498..b4c19cc 100644 --- a/zypp/repo/RepoException.cc +++ b/zypp/repo/RepoException.cc @@ -12,6 +12,7 @@ #include #include "zypp/repo/RepoException.h" #include "zypp/base/String.h" +#include "zypp/base/Gettext.h" using std::endl; @@ -106,19 +107,28 @@ namespace zypp /////////////////////////////////////////////////////////////////// #define DEF_CTORS( CLASS, MSG ) \ - CLASS::CLASS() : ServiceException( MSG ) {} \ - CLASS::CLASS( const std::string & msg_r ) : ServiceException( msg_r ) {} \ - CLASS::CLASS( const ServiceInfo & service_r ) : ServiceException( service_r, MSG ) {} \ - CLASS::CLASS( const ServiceInfo & service_r, const std::string & msg_r ) : ServiceException( service_r, msg_r ) {} + CLASS::CLASS() : DEF_BASECLASS( MSG ) {} \ + CLASS::CLASS( const std::string & msg_r ) : DEF_BASECLASS( msg_r ) {} \ + CLASS::CLASS( const ServiceInfo & service_r ) : DEF_BASECLASS( service_r, MSG ) {} \ + CLASS::CLASS( const ServiceInfo & service_r, const std::string & msg_r ) : DEF_BASECLASS( service_r, msg_r ) {} +#define DEF_BASECLASS ServiceException DEF_CTORS( ServiceNoAliasException, "Service has no alias defined." ); DEF_CTORS( ServiceInvalidAliasException, "Service has an invalid alias." ); DEF_CTORS( ServiceAlreadyExistsException, "Service already exists." ); DEF_CTORS( ServiceNoUrlException, "Service has no or invalid url defined." ); - DEF_CTORS( ServicePluginInformalException,"Service plugin has trouble providing the metadata but this should not be treated as error." ); -#undef DEF_CTORS + // sub classes: + DEF_CTORS( ServicePluginException, "PLUGIN service exception." ); + + /////////////////////////////////////////////////////////////////// + // sub class: ServicePluginException +#undef DEF_BASECLASS +#define DEF_BASECLASS ServicePluginException + DEF_CTORS( ServicePluginInformalException, "Service plugin has trouble providing the metadata but this should not be treated as error." ); + DEF_CTORS( ServicePluginImmutableException, _("Service plugin does not support changing an attribute.") ); +#undef DEF_CTORS ///////////////////////////////////////////////////////////////// } // namespace repo /////////////////////////////////////////////////////////////////// diff --git a/zypp/repo/RepoException.h b/zypp/repo/RepoException.h index 00d5a94..daf97a3 100644 --- a/zypp/repo/RepoException.h +++ b/zypp/repo/RepoException.h @@ -239,10 +239,27 @@ namespace zypp ServiceNoUrlException( const ServiceInfo & service_r ); ServiceNoUrlException( const ServiceInfo & service_r, const std::string & msg_r ); }; + //@} + + + /** \name PLUGIN Service related exceptions. + */ + //@{ + + /** PLUGIN Service related exceptions + */ + class ServicePluginException : public ServiceException + { + public: + ServicePluginException(); + ServicePluginException( const std::string & msg_r ); + ServicePluginException( const ServiceInfo & service_r ); + ServicePluginException( const ServiceInfo & service_r, const std::string & msg_r ); + }; /** Service plugin has trouble providing the metadata but this should not be treated as error. */ - class ServicePluginInformalException : public ServiceException + class ServicePluginInformalException : public ServicePluginException { public: ServicePluginInformalException(); @@ -251,6 +268,16 @@ namespace zypp ServicePluginInformalException( const ServiceInfo & service_r, const std::string & msg_r ); }; + /** Service plugin is immutable. + */ + class ServicePluginImmutableException : public ServicePluginException + { + public: + ServicePluginImmutableException(); + ServicePluginImmutableException( const std::string & msg_r ); + ServicePluginImmutableException( const ServiceInfo & service_r ); + ServicePluginImmutableException( const ServiceInfo & service_r, const std::string & msg_r ); + }; //@} ///////////////////////////////////////////////////////////////// -- 2.7.4