Unify RepoExceptions
authorMichael Andres <ma@suse.de>
Thu, 6 Nov 2008 21:17:41 +0000 (21:17 +0000)
committerMichael Andres <ma@suse.de>
Thu, 6 Nov 2008 21:17:41 +0000 (21:17 +0000)
zypp/RepoInfo.h
zypp/repo/RepoException.cc
zypp/repo/RepoException.h

index b7b1a36..2e97b86 100644 (file)
@@ -111,6 +111,11 @@ namespace zypp
        */
       urls_const_iterator baseUrlsEnd() const;
       /**
+       * Pars pro toto: The first repository url
+       */
+      Url url() const
+      { return( baseUrlsEmpty() ? Url() : *baseUrlsBegin()); }
+      /**
        * A Url under which the metadata are located, or a set of mirrors.
        *
        * This can't be empty in order the repository to be valid
index c99383a..586e5ef 100644 (file)
@@ -10,7 +10,6 @@
  *
 */
 #include <iostream>
-//#include "zypp/base/Logger.h"
 #include "zypp/repo/RepoException.h"
 #include "zypp/base/String.h"
 
@@ -41,31 +40,38 @@ namespace zypp
     : Exception( "Repo exception" ), _info( info )
     {}
 
-    RepoException::RepoException( const RepoInfo & info,
-        const std::string& msg_r )
+    RepoException::RepoException( const RepoInfo & info, const std::string& msg_r )
     : Exception( msg_r ), _info( info )
     {}
 
-    RepoNotCachedException::RepoNotCachedException( const RepoInfo& info )
-    : RepoException( info, "Repository not Cached" )
-    {}
-
-    RepoNotCachedException::RepoNotCachedException(  const RepoInfo& info,
-        const std::string & msg_r )
-    : RepoException( info, msg_r )
-    {}
-
-    RepoUnknownTypeException::RepoUnknownTypeException( const RepoInfo &info)
-    : RepoException( info,
-        str::form("Cannot determine type for repository %s.",info.alias().c_str()))
+    RepoException::~RepoException() throw()
     {}
 
     std::ostream & RepoException::dumpOn( std::ostream & str ) const
     {
+      str << "[" << _info.alias() << "|" << _info.url() << "] ";
       return Exception::dumpOn( str );
     }
 
     ///////////////////////////////////////////////////////////////////
+
+#define DEF_CTORS( CLASS, MSG ) \
+    CLASS::CLASS()                                                        : RepoException( MSG ) {} \
+    CLASS::CLASS( const std::string & msg_r )                             : RepoException( msg_r ) {} \
+    CLASS::CLASS( const RepoInfo & service_r )                            : RepoException( service_r, MSG ) {} \
+    CLASS::CLASS( const RepoInfo & service_r, const std::string & msg_r ) : RepoException( service_r, msg_r ) {}
+
+    DEF_CTORS( RepoNotCachedException,      "Repository is not cached" );
+    DEF_CTORS( RepoNoUrlException,          "Repository has no or invalid url defined." );
+    DEF_CTORS( RepoNoAliasException,        "Repository has no alias defined." );
+    DEF_CTORS( RepoNotFoundException,       "Repository not found." );
+    DEF_CTORS( RepoAlreadyExistsException,  "Repository already exists." );
+    DEF_CTORS( RepoUnknownTypeException,    "Repository type can't be determined." );
+    DEF_CTORS( RepoMetadataException,       "Repository metadata not usable." );
+
+#undef DEF_CTORS
+
+    ///////////////////////////////////////////////////////////////////
     //
     // Service related exceptions
     //
index 4ced39e..d910ebd 100644 (file)
@@ -36,26 +36,24 @@ namespace zypp
      */
     class RepoException : public Exception
     {
-    public:
-      /** Default ctor */
-      RepoException();
-      /** Ctor */
-      RepoException( const std::string & msg_r );
-
-      RepoException( const RepoInfo & info );
-
-      RepoException( const RepoInfo & info, const std::string & msg_r );
+      public:
+        RepoException();
+        RepoException( const std::string & msg_r );
+        RepoException( const RepoInfo & info );
+        RepoException( const RepoInfo & info, const std::string & msg_r );
+        virtual ~RepoException() throw();
 
-      virtual ~RepoException() throw() {}
+        RepoInfo info()
+        { return _info; }
 
-      RepoInfo info()
-      { return _info; }
+        std::string alias()
+        { return info().alias(); }
 
-    protected:
-      virtual std::ostream & dumpOn( std::ostream & str ) const;
+      protected:
+        virtual std::ostream & dumpOn( std::ostream & str ) const;
 
-    private:
-      RepoInfo _info;
+      private:
+        RepoInfo _info;
     };
     ///////////////////////////////////////////////////////////////////
 
@@ -66,9 +64,11 @@ namespace zypp
      */
     class RepoNotCachedException : public RepoException
     {
-    public:
-      RepoNotCachedException( const RepoInfo& info );
-      RepoNotCachedException( const RepoInfo& info, const std::string & msg_r );
+      public:
+        RepoNotCachedException();
+        RepoNotCachedException( const std::string & msg_r );
+        RepoNotCachedException( const RepoInfo & info );
+        RepoNotCachedException( const RepoInfo & info, const std::string & msg_r );
     };
 
     /**
@@ -78,13 +78,10 @@ namespace zypp
     class RepoNoUrlException : public RepoException
     {
       public:
-      RepoNoUrlException()
-      {}
-
-      RepoNoUrlException( const RepoInfo &info)
-        : RepoException(info)
-        {}
-
+        RepoNoUrlException();
+        RepoNoUrlException( const std::string & msg_r );
+        RepoNoUrlException( const RepoInfo & info );
+        RepoNoUrlException( const RepoInfo & info, const std::string & msg_r );
     };
 
     /**
@@ -93,7 +90,11 @@ namespace zypp
      */
     class RepoNoAliasException : public RepoException
     {
-
+      public:
+        RepoNoAliasException();
+        RepoNoAliasException( const std::string & msg_r );
+        RepoNoAliasException( const RepoInfo & info );
+        RepoNoAliasException( const RepoInfo & info, const std::string & msg_r );
     };
 
     /**
@@ -102,10 +103,11 @@ namespace zypp
      */
     class RepoNotFoundException : public RepoException
     {
-    public:
-      RepoNotFoundException( const RepoInfo &info)
-        : RepoException(info)
-      {}
+      public:
+        RepoNotFoundException();
+        RepoNotFoundException( const std::string & msg_r );
+        RepoNotFoundException( const RepoInfo & info );
+        RepoNotFoundException( const RepoInfo & info, const std::string & msg_r );
     };
 
     /**
@@ -114,18 +116,11 @@ namespace zypp
      */
     class RepoAlreadyExistsException : public RepoException
     {
-    public:
-      RepoAlreadyExistsException( const RepoInfo &info,
-                                  const std::string & msg_r )
-        : RepoException(info,msg_r)
-      {}
-
-      RepoAlreadyExistsException( const RepoInfo &info )
-        : RepoException(info)
-      {}
-
-      std::string alias()
-      { return info().alias(); }
+      public:
+        RepoAlreadyExistsException();
+        RepoAlreadyExistsException( const std::string & msg_r );
+        RepoAlreadyExistsException( const RepoInfo & info );
+        RepoAlreadyExistsException( const RepoInfo & info, const std::string & msg_r );
     };
 
     /**
@@ -134,16 +129,11 @@ namespace zypp
      */
     class RepoUnknownTypeException : public RepoException
     {
-    public:
-      RepoUnknownTypeException( const std::string & msg_r )
-        : RepoException(msg_r)
-      {}
-
-      RepoUnknownTypeException( const RepoInfo &info );
-
-      RepoUnknownTypeException()
-      {}
-
+      public:
+        RepoUnknownTypeException();
+        RepoUnknownTypeException( const std::string & msg_r );
+        RepoUnknownTypeException( const RepoInfo & info );
+        RepoUnknownTypeException( const RepoInfo & info, const std::string & msg_r );
     };
 
     /**
@@ -152,13 +142,11 @@ namespace zypp
      */
     class RepoMetadataException : public RepoException
     {
-    public:
-      RepoMetadataException( const RepoInfo &info)
-        : RepoException(info)
-      {}
-
-      RepoMetadataException()
-      {}
+      public:
+        RepoMetadataException();
+        RepoMetadataException( const std::string & msg_r );
+        RepoMetadataException( const RepoInfo & info );
+        RepoMetadataException( const RepoInfo & info, const std::string & msg_r );
     };
 
     //@}
@@ -184,7 +172,10 @@ namespace zypp
         ServiceInfo service()
         { return _service; }
 
-      protected:
+        std::string alias()
+        { return service().alias(); }
+
+     protected:
         virtual std::ostream & dumpOn( std::ostream & str ) const;
 
       private: