Imported Upstream version 17.14.0
[platform/upstream/libzypp.git] / zypp / media / MediaException.h
index 8c7cd20..18e6689 100644 (file)
 #include <iosfwd>
 
 #include <string>
+#include <vector>
 
 #include "zypp/base/Exception.h"
 #include "zypp/Pathname.h"
 #include "zypp/Url.h"
+#include "zypp/ByteCount.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -36,8 +38,7 @@ namespace zypp
       /** Ctor taking message.
        * Use \ref ZYPP_THROW to throw exceptions.
       */
-      MediaException()
-      : Exception( "Media Exception" )
+      MediaException() : Exception( "Media Exception" )
       {}
       /** Ctor taking message.
        * Use \ref ZYPP_THROW to throw exceptions.
@@ -45,39 +46,57 @@ namespace zypp
       MediaException( const std::string & msg_r )
       : Exception( msg_r )
       {}
+
       /** Dtor. */
-      virtual ~MediaException() throw() {};
+      virtual ~MediaException() noexcept override;
     };
 
     class MediaMountException : public MediaException
     {
     public:
+      MediaMountException()
+      : MediaException( "Media Mount Exception" )
+      {}
+
       /** Ctor taking message.
-       * Use \ref ZYPP_DOTHROW to throw exceptions.
+       * Use \ref ZYPP_THROW to throw exceptions.
       */
       MediaMountException( const std::string & error_r,
                           const std::string & source_r,
-                          const std::string & target_r )
+                          const std::string & target_r,
+                          const std::string & cmdout_r="")
       : MediaException()
       , _error(error_r)
       , _source(source_r)
       , _target(target_r)
+      , _cmdout(cmdout_r)
       {}
       /** Dtor. */
-      virtual ~MediaMountException() throw() {};
+      virtual ~MediaMountException() noexcept {}
+
+      const std::string & mountError() const
+      { return _error;  }
+      const std::string & mountSource() const
+      { return _source; }
+      const std::string & mountTarget() const
+      { return _target; }
+      const std::string & mountOutput() const
+      { return _cmdout; }
+
     protected:
       virtual std::ostream & dumpOn( std::ostream & str ) const;
     private:
       std::string _error;
       std::string _source;
       std::string _target;
+      std::string _cmdout;
     };
 
     class MediaUnmountException : public MediaException
     {
     public:
       /** Ctor taking message.
-       * Use \ref ZYPP_DOTHROW to throw exceptions.
+       * Use \ref ZYPP_THROW to throw exceptions.
       */
       MediaUnmountException( const std::string & error_r,
                             const std::string & path_r )
@@ -86,7 +105,7 @@ namespace zypp
       , _path(path_r)
       {}
       /** Dtor. */
-      virtual ~MediaUnmountException() throw() {};
+      virtual ~MediaUnmountException() noexcept {}
     protected:
       virtual std::ostream & dumpOn( std::ostream & str ) const;
     private:
@@ -101,7 +120,7 @@ namespace zypp
       : MediaException()
       , _filename(filename_r)
       {}
-      virtual ~MediaBadFilenameException() throw() {};
+      virtual ~MediaBadFilenameException() noexcept {}
       std::string filename() const { return _filename; }
     protected:
       virtual std::ostream & dumpOn( std::ostream & str ) const;
@@ -112,13 +131,15 @@ namespace zypp
     class MediaNotOpenException : public MediaException
     {
     public:
-      MediaNotOpenException()
+      MediaNotOpenException(const std::string & action_r)
       : MediaException()
+      , _action(action_r)
       {}
-      virtual ~MediaNotOpenException() throw() {};
+      virtual ~MediaNotOpenException() noexcept {}
     protected:
       virtual std::ostream & dumpOn( std::ostream & str ) const;
     private:
+      std::string _action;
     };
 
     class MediaFileNotFoundException : public MediaException
@@ -127,10 +148,10 @@ namespace zypp
       MediaFileNotFoundException(const Url & url_r,
                                 const Pathname & filename_r)
       : MediaException()
-      , _url(url_r.toString())
+      , _url(url_r.asString())
       , _filename(filename_r.asString())
       {}
-      virtual ~MediaFileNotFoundException() throw() {};
+      virtual ~MediaFileNotFoundException() noexcept {}
     protected:
       virtual std::ostream & dumpOn( std::ostream & str ) const;
     private:
@@ -145,7 +166,7 @@ namespace zypp
       : MediaException()
       , _filename(filename_r.asString())
       {}
-      virtual ~MediaWriteException() throw() {};
+      virtual ~MediaWriteException() noexcept {}
     protected:
       virtual std::ostream & dumpOn( std::ostream & str ) const;
     private:
@@ -157,9 +178,37 @@ namespace zypp
     public:
       MediaNotAttachedException(const Url & url_r)
       : MediaException()
-      , _url(url_r.toString())
+      , _url(url_r.asString())
       {}
-      virtual ~MediaNotAttachedException() throw() {};
+      virtual ~MediaNotAttachedException() noexcept {}
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+    private:
+      std::string _url;
+    };
+
+    class MediaBadAttachPointException : public MediaException
+    {
+    public:
+      MediaBadAttachPointException(const Url & url_r)
+      : MediaException()
+      , _url(url_r.asString())
+      {}
+      virtual ~MediaBadAttachPointException() noexcept {}
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+    private:
+      std::string _url;
+    };
+
+    class MediaCurlInitException : public MediaException
+    {
+    public:
+      MediaCurlInitException(const Url & url_r)
+      : MediaException()
+      , _url(url_r.asString())
+      {}
+      virtual ~MediaCurlInitException() noexcept {}
     protected:
       virtual std::ostream & dumpOn( std::ostream & str ) const;
     private:
@@ -172,10 +221,10 @@ namespace zypp
       MediaSystemException(const Url & url_r,
                           const std::string & message_r)
       : MediaException()
-      , _url(url_r.toString())
+      , _url(url_r.asString())
       , _message(message_r)
       {}
-      virtual ~MediaSystemException() throw() {};
+      virtual ~MediaSystemException() noexcept {}
     protected:
       virtual std::ostream & dumpOn( std::ostream & str ) const;
     private:
@@ -189,10 +238,10 @@ namespace zypp
       MediaNotAFileException(const Url & url_r,
                             const Pathname & path_r)
       : MediaException()
-      , _url(url_r.toString())
+      , _url(url_r.asString())
       , _path(path_r.asString())
       {}
-      virtual ~MediaNotAFileException() throw() {};
+      virtual ~MediaNotAFileException() noexcept {}
     protected:
       virtual std::ostream & dumpOn( std::ostream & str ) const;
     private:
@@ -206,10 +255,10 @@ namespace zypp
       MediaNotADirException(const Url & url_r,
                            const Pathname & path_r)
       : MediaException()
-      , _url(url_r.toString())
+      , _url(url_r.asString())
       , _path(path_r.asString())
       {}
-      virtual ~MediaNotADirException() throw() {};
+      virtual ~MediaNotADirException() noexcept {}
     protected:
       virtual std::ostream & dumpOn( std::ostream & str ) const;
     private:
@@ -220,18 +269,269 @@ namespace zypp
     class MediaBadUrlException : public MediaException
     {
     public:
-      MediaBadUrlException(const Url & url_r)
+      MediaBadUrlException(const Url & url_r,
+                           const std::string &msg_r = std::string())
       : MediaException()
-      , _url(url_r.toString())
+      , _url(url_r.asString())
+      , _msg(msg_r)
+      {}
+      virtual ~MediaBadUrlException() noexcept {}
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+      std::string _url;
+      std::string _msg;
+    };
+
+    class MediaBadUrlEmptyHostException : public MediaBadUrlException
+    {
+    public:
+      MediaBadUrlEmptyHostException(const Url & url_r)
+      : MediaBadUrlException(url_r)
       {}
-      virtual ~MediaBadUrlException() throw() {};
+      virtual ~MediaBadUrlEmptyHostException() noexcept {}
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+    };
+
+    class MediaBadUrlEmptyFilesystemException : public MediaBadUrlException
+    {
+    public:
+      MediaBadUrlEmptyFilesystemException(const Url & url_r)
+      : MediaBadUrlException(url_r)
+      {}
+      virtual ~MediaBadUrlEmptyFilesystemException() noexcept {}
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+    };
+
+    class MediaBadUrlEmptyDestinationException : public MediaBadUrlException
+    {
+    public:
+      MediaBadUrlEmptyDestinationException(const Url & url_r)
+      : MediaBadUrlException(url_r)
+      {}
+      virtual ~MediaBadUrlEmptyDestinationException() noexcept {}
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+    };
+
+    class MediaUnsupportedUrlSchemeException : public MediaBadUrlException
+    {
+    public:
+      MediaUnsupportedUrlSchemeException(const Url & url_r)
+      : MediaBadUrlException(url_r)
+      {}
+      virtual ~MediaUnsupportedUrlSchemeException() noexcept {}
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+    };
+
+    class MediaNotSupportedException : public MediaException
+    {
+    public:
+      MediaNotSupportedException(const Url & url_r)
+      : MediaException()
+      , _url(url_r.asString())
+      {}
+      virtual ~MediaNotSupportedException() noexcept {}
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+      std::string _url;
+    };
+
+    class MediaCurlException : public MediaException
+    {
+    public:
+      MediaCurlException(const Url & url_r,
+                        const std::string & err_r,
+                        const std::string & msg_r)
+      : MediaException()
+      , _url(url_r.asString())
+      , _err(err_r)
+      , _msg(msg_r)
+      {}
+      virtual ~MediaCurlException() noexcept {}
+      std::string errstr() const { return _err; }
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+      std::string _url;
+      std::string _err;
+      std::string _msg;
+    };
+
+    class MediaCurlSetOptException : public MediaException
+    {
+    public:
+      MediaCurlSetOptException(const Url & url_r, const std::string & msg_r)
+      : MediaException()
+      , _url(url_r.asString())
+      , _msg(msg_r)
+      {}
+      virtual ~MediaCurlSetOptException() noexcept {}
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+      std::string _url;
+      std::string _msg;
+    };
+
+    class MediaNotDesiredException : public MediaException
+    {
+    public:
+      MediaNotDesiredException(const Url & url_r)
+      : MediaException()
+      , _url(url_r.asString())
+      {}
+      virtual ~MediaNotDesiredException() noexcept {}
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+    private:
+      std::string  _url;
+    };
+
+    class MediaIsSharedException : public MediaException
+    {
+    public:
+      /**
+       * \param name A media source as string (see MediaSource class).
+       */
+      MediaIsSharedException(const std::string &name)
+      : MediaException()
+      , _name(name)
+      {}
+      virtual ~MediaIsSharedException() noexcept {}
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+    private:
+      std::string _name;
+    };
+
+    class MediaNotEjectedException: public MediaException
+    {
+    public:
+      MediaNotEjectedException()
+      : MediaException("Can't eject any media")
+      , _name("")
+      {}
+
+      MediaNotEjectedException(const std::string &name)
+      : MediaException("Can't eject media")
+      , _name(name)
+      {}
+      virtual ~MediaNotEjectedException() noexcept {}
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+    private:
+      std::string _name;
+    };
+
+    class MediaUnauthorizedException: public MediaException
+    {
+    public:
+      MediaUnauthorizedException()
+      : MediaException("Unauthorized media access")
+      , _url("")
+      , _err("")
+      , _hint("")
+      {}
+
+      MediaUnauthorizedException(const Url         &url_r,
+                                 const std::string &msg_r,
+                                 const std::string &err_r,
+                                 const std::string &hint_r)
+      : MediaException(msg_r)
+      , _url(url_r)
+      , _err(err_r)
+      , _hint(hint_r)
+      {}
+
+      virtual ~MediaUnauthorizedException() noexcept {}
+
+      const Url         & url()  const { return _url;  }
+      const std::string & err()  const { return _err;  }
+      /** comma separated list of available authentication types */
+      const std::string & hint() const { return _hint; }
+
     protected:
       virtual std::ostream & dumpOn( std::ostream & str ) const;
     private:
+      Url         _url;
+      std::string _err;
+      std::string _hint;
+    };
+
+    class MediaForbiddenException : public MediaException
+    {
+    public:
+      MediaForbiddenException(const Url & url_r, const std::string & msg = "")
+      : MediaException(msg)
+      , _url(url_r.asString()), _msg(msg)
+      {}
+      virtual ~MediaForbiddenException() noexcept {}
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+      std::string _url;
+      std::string _msg;
+    };
+
+    class MediaTimeoutException : public MediaException
+    {
+    public:
+      MediaTimeoutException(const Url & url_r, const std::string & msg = "")
+      : MediaException(msg)
+      , _url(url_r.asString()), _msg(msg)
+      {}
+      virtual ~MediaTimeoutException() noexcept {}
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+      std::string _url;
+      std::string _msg;
+    };
+
+    class MediaFileSizeExceededException : public MediaException
+    {
+    public:
+      MediaFileSizeExceededException(const Url & url_r, const ByteCount &cnt_r, const std::string & msg = "")
+      : MediaException(msg)
+      , _url(url_r.asString())
+      , _msg(msg)
+      , _expectedFileSize(cnt_r)
+      {}
+      virtual ~MediaFileSizeExceededException() noexcept {}
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+      std::string _url;
+      std::string _msg;
+      ByteCount _expectedFileSize;
+    };
+
+    /** For HTTP 503 and similar. */
+    class MediaTemporaryProblemException : public MediaException
+    {
+    public:
+      MediaTemporaryProblemException(const Url & url_r, const std::string & msg = "")
+      : MediaException(msg)
+      , _url(url_r.asString()), _msg(msg)
+      {}
+      virtual ~MediaTemporaryProblemException() noexcept {}
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
       std::string _url;
+      std::string _msg;
     };
 
-    
+    class MediaBadCAException : public MediaException
+    {
+    public:
+      MediaBadCAException(const Url & url_r, const std::string & msg = "")
+      : MediaException(msg)
+      , _url(url_r.asString()), _msg(msg)
+      {}
+      virtual ~MediaBadCAException() noexcept {}
+    protected:
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+      std::string _url;
+      std::string _msg;
+    };
 
   /////////////////////////////////////////////////////////////////
   } // namespace media