libzypp 17.25.10
RepoException.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
14 #include <zypp/base/String.h>
15 #include <zypp/base/Gettext.h>
16 
17 using std::endl;
18 
20 namespace zypp
21 {
23  namespace repo
24  {
25 
27  //
28  // Repository related exceptions
29  //
31 
33  : Exception( "Repo exception" )
34  {}
35 
36  RepoException::RepoException( const std::string & msg_r )
37  : Exception( msg_r )
38  {}
39 
41  : Exception( "Repo exception" ), _info( info )
42  {}
43 
44  RepoException::RepoException( const RepoInfo & info, const std::string& msg_r )
45  : Exception( msg_r ), _info( info )
46  {}
47 
49  {}
50 
51  std::ostream & RepoException::dumpOn( std::ostream & str ) const
52  {
53  str << "[" << _info.alias() << "|" << _info.url() << "] ";
54  return Exception::dumpOn( str );
55  }
56 
58 
59 #define DEF_CTORS( CLASS, MSG ) \
60  CLASS::CLASS() : RepoException( MSG ) {} \
61  CLASS::CLASS( const std::string & msg_r ) : RepoException( msg_r ) {} \
62  CLASS::CLASS( const RepoInfo & service_r ) : RepoException( service_r, MSG ) {} \
63  CLASS::CLASS( const RepoInfo & service_r, const std::string & msg_r ) : RepoException( service_r, msg_r ) {}
64 
65  DEF_CTORS( RepoNotCachedException, "Repository is not cached" );
66  DEF_CTORS( RepoNoUrlException, "Repository has no or invalid url defined." );
67  DEF_CTORS( RepoNoAliasException, "Repository has no alias defined." );
68  DEF_CTORS( RepoInvalidAliasException, "Repository has an invalid alias." );
69  DEF_CTORS( RepoNotFoundException, "Repository not found." );
70  DEF_CTORS( RepoAlreadyExistsException, "Repository already exists." );
71  DEF_CTORS( RepoUnknownTypeException, "Repository type can't be determined." );
72  DEF_CTORS( RepoMetadataException, "Repository metadata not usable." );
73 
74 #undef DEF_CTORS
75 
77  //
78  // Service related exceptions
79  //
81 
83  : Exception( "Service exception" )
84  {}
85 
86  ServiceException::ServiceException( const std::string & msg_r )
87  : Exception( msg_r )
88  {}
89 
91  : Exception( "Service exception" ), _service( service_r )
92  {}
93 
94  ServiceException::ServiceException( const ServiceInfo & service_r, const std::string & msg_r )
95  : Exception( msg_r ), _service( service_r )
96  {}
97 
99  {}
100 
101  std::ostream & ServiceException::dumpOn( std::ostream & str ) const
102  {
103  str << "[" << _service.alias() << "|" << _service.url() << "] ";
104  return Exception::dumpOn( str );
105  }
106 
108 
109 #define DEF_CTORS( CLASS, MSG ) \
110  CLASS::CLASS() : DEF_BASECLASS( MSG ) {} \
111  CLASS::CLASS( const std::string & msg_r ) : DEF_BASECLASS( msg_r ) {} \
112  CLASS::CLASS( const ServiceInfo & service_r ) : DEF_BASECLASS( service_r, MSG ) {} \
113  CLASS::CLASS( const ServiceInfo & service_r, const std::string & msg_r ) : DEF_BASECLASS( service_r, msg_r ) {}
114 
115 #define DEF_BASECLASS ServiceException
116  DEF_CTORS( ServiceNoAliasException, "Service has no alias defined." );
117  DEF_CTORS( ServiceInvalidAliasException, "Service has an invalid alias." );
118  DEF_CTORS( ServiceAlreadyExistsException, "Service already exists." );
119  DEF_CTORS( ServiceNoUrlException, "Service has no or invalid url defined." );
120 
121  // sub classes:
122  DEF_CTORS( ServicePluginException, "PLUGIN service exception." );
123 
125  // sub class: ServicePluginException
126 #undef DEF_BASECLASS
127 #define DEF_BASECLASS ServicePluginException
128  DEF_CTORS( ServicePluginInformalException, "Service plugin has trouble providing the metadata but this should not be treated as error." );
129  DEF_CTORS( ServicePluginImmutableException, _("Service plugin does not support changing an attribute.") );
130 
131 #undef DEF_CTORS
133  } // namespace repo
136 } // namespace zypp
Interface to gettext.
#define _(MSG)
Definition: Gettext.h:37
Base class for Exception.
Definition: Exception.h:146
virtual std::ostream & dumpOn(std::ostream &str) const
Overload this to print a proper error message.
Definition: Exception.cc:141
What is known about a repository.
Definition: RepoInfo.h:72
Url url() const
Pars pro toto: The first repository url.
Definition: RepoInfo.h:131
Service data.
Definition: ServiceInfo.h:37
Url url() const
The service url.
Definition: ServiceInfo.cc:99
Repository already exists and some unique attribute can't be duplicated.
virtual std::ostream & dumpOn(std::ostream &str) const
Overload this to print a proper error message.
std::string alias() const
unique identifier for this source.
Thrown when the repo alias is found to be invalid.
thrown when it was impossible to use the raw metadata for this repo.
thrown when it was impossible to determine an alias for this repo.
Definition: RepoException.h:92
thrown when it was impossible to determine one url for this repo.
Definition: RepoException.h:79
The repository cache is not built yet so you can't create the repostories from the cache.
Definition: RepoException.h:66
thrown when it was impossible to match a repository
thrown when it was impossible to determine this repo type.
Service already exists and some unique attribute can't be duplicated.
virtual std::ostream & dumpOn(std::ostream &str) const
Overload this to print a proper error message.
Thrown when the repo alias is found to be invalid.
Service without alias was used in an operation.
Service has no or invalid url defined.
PLUGIN Service related exceptions.
Service plugin has trouble providing the metadata but this should not be treated as error.
String related utilities and Regular expression matching.
DEF_CTORS(RepoNotCachedException, "Repository is not cached")
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2