1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/media/MediaException.h
12 #ifndef ZYPP_MEDIA_MEDIAEXCEPTION_H
13 #define ZYPP_MEDIA_MEDIAEXCEPTION_H
20 #include "zypp/base/Exception.h"
21 #include "zypp/Pathname.h"
23 #include "zypp/ByteCount.h"
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
29 ///////////////////////////////////////////////////////////////
31 // CLASS NAME : MediaException
32 /** Just inherits Exception to separate media exceptions
35 class MediaException : public Exception
38 /** Ctor taking message.
39 * Use \ref ZYPP_THROW to throw exceptions.
41 MediaException() : Exception( "Media Exception" )
43 /** Ctor taking message.
44 * Use \ref ZYPP_THROW to throw exceptions.
46 MediaException( const std::string & msg_r )
51 virtual ~MediaException() throw() {};
54 class MediaMountException : public MediaException
58 : MediaException( "Media Mount Exception" )
61 /** Ctor taking message.
62 * Use \ref ZYPP_THROW to throw exceptions.
64 MediaMountException( const std::string & error_r,
65 const std::string & source_r,
66 const std::string & target_r,
67 const std::string & cmdout_r="")
75 virtual ~MediaMountException() throw() {};
77 const std::string & mountError() const
79 const std::string & mountSource() const
81 const std::string & mountTarget() const
83 const std::string & mountOutput() const
87 virtual std::ostream & dumpOn( std::ostream & str ) const;
95 class MediaUnmountException : public MediaException
98 /** Ctor taking message.
99 * Use \ref ZYPP_THROW to throw exceptions.
101 MediaUnmountException( const std::string & error_r,
102 const std::string & path_r )
108 virtual ~MediaUnmountException() throw() {};
110 virtual std::ostream & dumpOn( std::ostream & str ) const;
116 class MediaBadFilenameException : public MediaException
119 MediaBadFilenameException(const std::string & filename_r)
121 , _filename(filename_r)
123 virtual ~MediaBadFilenameException() throw() {};
124 std::string filename() const { return _filename; }
126 virtual std::ostream & dumpOn( std::ostream & str ) const;
128 std::string _filename;
131 class MediaNotOpenException : public MediaException
134 MediaNotOpenException(const std::string & action_r)
138 virtual ~MediaNotOpenException() throw() {};
140 virtual std::ostream & dumpOn( std::ostream & str ) const;
145 class MediaFileNotFoundException : public MediaException
148 MediaFileNotFoundException(const Url & url_r,
149 const Pathname & filename_r)
151 , _url(url_r.asString())
152 , _filename(filename_r.asString())
154 virtual ~MediaFileNotFoundException() throw() {};
156 virtual std::ostream & dumpOn( std::ostream & str ) const;
159 std::string _filename;
162 class MediaWriteException : public MediaException
165 MediaWriteException(const Pathname & filename_r)
167 , _filename(filename_r.asString())
169 virtual ~MediaWriteException() throw() {};
171 virtual std::ostream & dumpOn( std::ostream & str ) const;
173 std::string _filename;
176 class MediaNotAttachedException : public MediaException
179 MediaNotAttachedException(const Url & url_r)
181 , _url(url_r.asString())
183 virtual ~MediaNotAttachedException() throw() {};
185 virtual std::ostream & dumpOn( std::ostream & str ) const;
190 class MediaBadAttachPointException : public MediaException
193 MediaBadAttachPointException(const Url & url_r)
195 , _url(url_r.asString())
197 virtual ~MediaBadAttachPointException() throw() {};
199 virtual std::ostream & dumpOn( std::ostream & str ) const;
204 class MediaCurlInitException : public MediaException
207 MediaCurlInitException(const Url & url_r)
209 , _url(url_r.asString())
211 virtual ~MediaCurlInitException() throw() {};
213 virtual std::ostream & dumpOn( std::ostream & str ) const;
218 class MediaSystemException : public MediaException
221 MediaSystemException(const Url & url_r,
222 const std::string & message_r)
224 , _url(url_r.asString())
225 , _message(message_r)
227 virtual ~MediaSystemException() throw() {};
229 virtual std::ostream & dumpOn( std::ostream & str ) const;
232 std::string _message;
235 class MediaNotAFileException : public MediaException
238 MediaNotAFileException(const Url & url_r,
239 const Pathname & path_r)
241 , _url(url_r.asString())
242 , _path(path_r.asString())
244 virtual ~MediaNotAFileException() throw() {};
246 virtual std::ostream & dumpOn( std::ostream & str ) const;
252 class MediaNotADirException : public MediaException
255 MediaNotADirException(const Url & url_r,
256 const Pathname & path_r)
258 , _url(url_r.asString())
259 , _path(path_r.asString())
261 virtual ~MediaNotADirException() throw() {};
263 virtual std::ostream & dumpOn( std::ostream & str ) const;
269 class MediaBadUrlException : public MediaException
272 MediaBadUrlException(const Url & url_r,
273 const std::string &msg_r = std::string())
275 , _url(url_r.asString())
278 virtual ~MediaBadUrlException() throw() {};
280 virtual std::ostream & dumpOn( std::ostream & str ) const;
285 class MediaBadUrlEmptyHostException : public MediaBadUrlException
288 MediaBadUrlEmptyHostException(const Url & url_r)
289 : MediaBadUrlException(url_r)
291 virtual ~MediaBadUrlEmptyHostException() throw() {};
293 virtual std::ostream & dumpOn( std::ostream & str ) const;
296 class MediaBadUrlEmptyFilesystemException : public MediaBadUrlException
299 MediaBadUrlEmptyFilesystemException(const Url & url_r)
300 : MediaBadUrlException(url_r)
302 virtual ~MediaBadUrlEmptyFilesystemException() throw() {};
304 virtual std::ostream & dumpOn( std::ostream & str ) const;
307 class MediaBadUrlEmptyDestinationException : public MediaBadUrlException
310 MediaBadUrlEmptyDestinationException(const Url & url_r)
311 : MediaBadUrlException(url_r)
313 virtual ~MediaBadUrlEmptyDestinationException() throw() {};
315 virtual std::ostream & dumpOn( std::ostream & str ) const;
318 class MediaUnsupportedUrlSchemeException : public MediaBadUrlException
321 MediaUnsupportedUrlSchemeException(const Url & url_r)
322 : MediaBadUrlException(url_r)
324 virtual ~MediaUnsupportedUrlSchemeException() throw() {};
326 virtual std::ostream & dumpOn( std::ostream & str ) const;
329 class MediaNotSupportedException : public MediaException
332 MediaNotSupportedException(const Url & url_r)
334 , _url(url_r.asString())
336 virtual ~MediaNotSupportedException() throw() {};
338 virtual std::ostream & dumpOn( std::ostream & str ) const;
342 class MediaCurlException : public MediaException
345 MediaCurlException(const Url & url_r,
346 const std::string & err_r,
347 const std::string & msg_r)
349 , _url(url_r.asString())
353 virtual ~MediaCurlException() throw() {};
354 std::string errstr() const { return _err; }
356 virtual std::ostream & dumpOn( std::ostream & str ) const;
362 class MediaCurlSetOptException : public MediaException
365 MediaCurlSetOptException(const Url & url_r, const std::string & msg_r)
367 , _url(url_r.asString())
370 virtual ~MediaCurlSetOptException() throw() {};
372 virtual std::ostream & dumpOn( std::ostream & str ) const;
377 class MediaNotDesiredException : public MediaException
380 MediaNotDesiredException(const Url & url_r)
382 , _url(url_r.asString())
384 virtual ~MediaNotDesiredException() throw() {};
386 virtual std::ostream & dumpOn( std::ostream & str ) const;
391 class MediaIsSharedException : public MediaException
395 * \param name A media source as string (see MediaSource class).
397 MediaIsSharedException(const std::string &name)
401 virtual ~MediaIsSharedException() throw() {};
403 virtual std::ostream & dumpOn( std::ostream & str ) const;
408 class MediaNotEjectedException: public MediaException
411 MediaNotEjectedException()
412 : MediaException("Can't eject any media")
416 MediaNotEjectedException(const std::string &name)
417 : MediaException("Can't eject media")
420 virtual ~MediaNotEjectedException() throw() {};
422 virtual std::ostream & dumpOn( std::ostream & str ) const;
427 class MediaUnauthorizedException: public MediaException
430 MediaUnauthorizedException()
431 : MediaException("Unauthorized media access")
437 MediaUnauthorizedException(const Url &url_r,
438 const std::string &msg_r,
439 const std::string &err_r,
440 const std::string &hint_r)
441 : MediaException(msg_r)
447 virtual ~MediaUnauthorizedException() throw() {};
449 const Url & url() const { return _url; }
450 const std::string & err() const { return _err; }
451 /** comma separated list of available authentication types */
452 const std::string & hint() const { return _hint; }
455 virtual std::ostream & dumpOn( std::ostream & str ) const;
462 class MediaForbiddenException : public MediaException
465 MediaForbiddenException(const Url & url_r, const std::string & msg = "")
466 : MediaException(msg)
467 , _url(url_r.asString()), _msg(msg)
469 virtual ~MediaForbiddenException() throw() {};
471 virtual std::ostream & dumpOn( std::ostream & str ) const;
476 class MediaTimeoutException : public MediaException
479 MediaTimeoutException(const Url & url_r, const std::string & msg = "")
480 : MediaException(msg)
481 , _url(url_r.asString()), _msg(msg)
483 virtual ~MediaTimeoutException() throw() {};
485 virtual std::ostream & dumpOn( std::ostream & str ) const;
490 class MediaFileSizeExceededException : public MediaException
493 MediaFileSizeExceededException(const Url & url_r, const ByteCount &cnt_r, const std::string & msg = "")
494 : MediaException(msg)
495 , _url(url_r.asString())
497 , _expectedFileSize(cnt_r)
499 virtual ~MediaFileSizeExceededException() throw() {};
501 virtual std::ostream & dumpOn( std::ostream & str ) const;
504 ByteCount _expectedFileSize;
507 /** For HTTP 503 and similar. */
508 class MediaTemporaryProblemException : public MediaException
511 MediaTemporaryProblemException(const Url & url_r, const std::string & msg = "")
512 : MediaException(msg)
513 , _url(url_r.asString()), _msg(msg)
515 virtual ~MediaTemporaryProblemException() throw() {};
517 virtual std::ostream & dumpOn( std::ostream & str ) const;
522 class MediaBadCAException : public MediaException
525 MediaBadCAException(const Url & url_r, const std::string & msg = "")
526 : MediaException(msg)
527 , _url(url_r.asString()), _msg(msg)
529 virtual ~MediaBadCAException() throw() {};
531 virtual std::ostream & dumpOn( std::ostream & str ) const;
537 * Thrown if /sbin/losetup fails to find an unused loop device for mounting
540 * UI hint: tell user to check permissions to read /dev/loop# or enablement
541 * of support for loop devices.
545 class MediaNoLoopDeviceException : public MediaException
548 MediaNoLoopDeviceException(const Url & url_r, const std::string & msg = "")
549 : MediaException(msg)
550 , _url(url_r.asString()), _msg(msg)
552 virtual ~MediaNoLoopDeviceException() throw() {};
554 virtual std::ostream & dumpOn( std::ostream & str ) const;
558 /////////////////////////////////////////////////////////////////
561 ///////////////////////////////////////////////////////////////////
562 #endif // ZYPP_MEDIA_MEDIAEXCEPTION_H