MediaNoLoopDeviceException: add optional explanatory message
[platform/upstream/libzypp.git] / zypp / media / MediaException.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/media/MediaException.h
10  *
11 */
12 #ifndef ZYPP_MEDIA_MEDIAEXCEPTION_H
13 #define ZYPP_MEDIA_MEDIAEXCEPTION_H
14
15 #include <iosfwd>
16
17 #include <string>
18 #include <vector>
19
20 #include "zypp/base/Exception.h"
21 #include "zypp/Pathname.h"
22 #include "zypp/Url.h"
23
24 ///////////////////////////////////////////////////////////////////
25 namespace zypp
26 { /////////////////////////////////////////////////////////////////
27   namespace media {
28     ///////////////////////////////////////////////////////////////
29     //
30     //  CLASS NAME : MediaException
31     /** Just inherits Exception to separate media exceptions
32      *
33      **/
34     class MediaException : public Exception
35     {
36     public:
37       /** Ctor taking message.
38        * Use \ref ZYPP_THROW to throw exceptions.
39       */
40       MediaException() : Exception( "Media Exception" )
41       {}
42       /** Ctor taking message.
43        * Use \ref ZYPP_THROW to throw exceptions.
44       */
45       MediaException( const std::string & msg_r )
46       : Exception( msg_r )
47       {}
48
49       /** Dtor. */
50       virtual ~MediaException() throw() {};
51     };
52
53     class MediaMountException : public MediaException
54     {
55     public:
56       MediaMountException()
57       : MediaException( "Media Mount Exception" )
58       {}
59
60       /** Ctor taking message.
61        * Use \ref ZYPP_THROW to throw exceptions.
62       */
63       MediaMountException( const std::string & error_r,
64                            const std::string & source_r,
65                            const std::string & target_r,
66                            const std::string & cmdout_r="")
67       : MediaException()
68       , _error(error_r)
69       , _source(source_r)
70       , _target(target_r)
71       , _cmdout(cmdout_r)
72       {}
73       /** Dtor. */
74       virtual ~MediaMountException() throw() {};
75
76       const std::string & mountError() const
77       { return _error;  }
78       const std::string & mountSource() const
79       { return _source; }
80       const std::string & mountTarget() const
81       { return _target; }
82       const std::string & mountOutput() const
83       { return _cmdout; }
84
85     protected:
86       virtual std::ostream & dumpOn( std::ostream & str ) const;
87     private:
88       std::string _error;
89       std::string _source;
90       std::string _target;
91       std::string _cmdout;
92     };
93
94     class MediaUnmountException : public MediaException
95     {
96     public:
97       /** Ctor taking message.
98        * Use \ref ZYPP_THROW to throw exceptions.
99       */
100       MediaUnmountException( const std::string & error_r,
101                              const std::string & path_r )
102       : MediaException()
103       , _error(error_r)
104       , _path(path_r)
105       {}
106       /** Dtor. */
107       virtual ~MediaUnmountException() throw() {};
108     protected:
109       virtual std::ostream & dumpOn( std::ostream & str ) const;
110     private:
111       std::string _error;
112       std::string _path;
113     };
114
115     class MediaBadFilenameException : public MediaException
116     {
117     public:
118       MediaBadFilenameException(const std::string & filename_r)
119       : MediaException()
120       , _filename(filename_r)
121       {}
122       virtual ~MediaBadFilenameException() throw() {};
123       std::string filename() const { return _filename; }
124     protected:
125       virtual std::ostream & dumpOn( std::ostream & str ) const;
126     private:
127       std::string _filename;
128     };
129
130     class MediaNotOpenException : public MediaException
131     {
132     public:
133       MediaNotOpenException(const std::string & action_r)
134       : MediaException()
135       , _action(action_r)
136       {}
137       virtual ~MediaNotOpenException() throw() {};
138     protected:
139       virtual std::ostream & dumpOn( std::ostream & str ) const;
140     private:
141       std::string _action;
142     };
143
144     class MediaFileNotFoundException : public MediaException
145     {
146     public:
147       MediaFileNotFoundException(const Url & url_r,
148                                  const Pathname & filename_r)
149       : MediaException()
150       , _url(url_r.asString())
151       , _filename(filename_r.asString())
152       {}
153       virtual ~MediaFileNotFoundException() throw() {};
154     protected:
155       virtual std::ostream & dumpOn( std::ostream & str ) const;
156     private:
157       std::string _url;
158       std::string _filename;
159     };
160
161     class MediaWriteException : public MediaException
162     {
163     public:
164       MediaWriteException(const Pathname & filename_r)
165       : MediaException()
166       , _filename(filename_r.asString())
167       {}
168       virtual ~MediaWriteException() throw() {};
169     protected:
170       virtual std::ostream & dumpOn( std::ostream & str ) const;
171     private:
172       std::string _filename;
173     };
174
175     class MediaNotAttachedException : public MediaException
176     {
177     public:
178       MediaNotAttachedException(const Url & url_r)
179       : MediaException()
180       , _url(url_r.asString())
181       {}
182       virtual ~MediaNotAttachedException() throw() {};
183     protected:
184       virtual std::ostream & dumpOn( std::ostream & str ) const;
185     private:
186       std::string _url;
187     };
188
189     class MediaBadAttachPointException : public MediaException
190     {
191     public:
192       MediaBadAttachPointException(const Url & url_r)
193       : MediaException()
194       , _url(url_r.asString())
195       {}
196       virtual ~MediaBadAttachPointException() throw() {};
197     protected:
198       virtual std::ostream & dumpOn( std::ostream & str ) const;
199     private:
200       std::string _url;
201     };
202
203     class MediaCurlInitException : public MediaException
204     {
205     public:
206       MediaCurlInitException(const Url & url_r)
207       : MediaException()
208       , _url(url_r.asString())
209       {}
210       virtual ~MediaCurlInitException() throw() {};
211     protected:
212       virtual std::ostream & dumpOn( std::ostream & str ) const;
213     private:
214       std::string _url;
215     };
216
217 class MediaMetalinkInitException : public MediaException
218     {
219     public:
220       MediaMetalinkInitException(const Url & url_r)
221       : MediaException()
222       , _url(url_r.asString())
223       {}
224       virtual ~MediaMetalinkInitException() throw() {};
225     protected:
226       virtual std::ostream & dumpOn( std::ostream & str ) const;
227     private:
228       std::string _url;
229     };
230
231 class MediaAria2cInitException : public MediaException
232     {
233     public:
234       MediaAria2cInitException(const Url & url_r)
235       : MediaException()
236       , _url(url_r.asString())
237       {}
238       virtual ~MediaAria2cInitException() throw() {};
239     protected:
240       virtual std::ostream & dumpOn( std::ostream & str ) const;
241     private:
242       std::string _url;
243     };
244
245     class MediaSystemException : public MediaException
246     {
247     public:
248       MediaSystemException(const Url & url_r,
249                            const std::string & message_r)
250       : MediaException()
251       , _url(url_r.asString())
252       , _message(message_r)
253       {}
254       virtual ~MediaSystemException() throw() {};
255     protected:
256       virtual std::ostream & dumpOn( std::ostream & str ) const;
257     private:
258       std::string _url;
259       std::string _message;
260     };
261
262     class MediaNotAFileException : public MediaException
263     {
264     public:
265       MediaNotAFileException(const Url & url_r,
266                              const Pathname & path_r)
267       : MediaException()
268       , _url(url_r.asString())
269       , _path(path_r.asString())
270       {}
271       virtual ~MediaNotAFileException() throw() {};
272     protected:
273       virtual std::ostream & dumpOn( std::ostream & str ) const;
274     private:
275       std::string _url;
276       std::string _path;
277     };
278
279     class MediaNotADirException : public MediaException
280     {
281     public:
282       MediaNotADirException(const Url & url_r,
283                             const Pathname & path_r)
284       : MediaException()
285       , _url(url_r.asString())
286       , _path(path_r.asString())
287       {}
288       virtual ~MediaNotADirException() throw() {};
289     protected:
290       virtual std::ostream & dumpOn( std::ostream & str ) const;
291     private:
292       std::string _url;
293       std::string _path;
294     };
295
296     class MediaBadUrlException : public MediaException
297     {
298     public:
299       MediaBadUrlException(const Url & url_r,
300                            const std::string &msg_r = std::string())
301       : MediaException()
302       , _url(url_r.asString())
303       , _msg(msg_r)
304       {}
305       virtual ~MediaBadUrlException() throw() {};
306     protected:
307       virtual std::ostream & dumpOn( std::ostream & str ) const;
308       std::string _url;
309       std::string _msg;
310     };
311
312     class MediaBadUrlEmptyHostException : public MediaBadUrlException
313     {
314     public:
315       MediaBadUrlEmptyHostException(const Url & url_r)
316       : MediaBadUrlException(url_r)
317       {}
318       virtual ~MediaBadUrlEmptyHostException() throw() {};
319     protected:
320       virtual std::ostream & dumpOn( std::ostream & str ) const;
321     };
322
323     class MediaBadUrlEmptyFilesystemException : public MediaBadUrlException
324     {
325     public:
326       MediaBadUrlEmptyFilesystemException(const Url & url_r)
327       : MediaBadUrlException(url_r)
328       {}
329       virtual ~MediaBadUrlEmptyFilesystemException() throw() {};
330     protected:
331       virtual std::ostream & dumpOn( std::ostream & str ) const;
332     };
333
334     class MediaBadUrlEmptyDestinationException : public MediaBadUrlException
335     {
336     public:
337       MediaBadUrlEmptyDestinationException(const Url & url_r)
338       : MediaBadUrlException(url_r)
339       {}
340       virtual ~MediaBadUrlEmptyDestinationException() throw() {};
341     protected:
342       virtual std::ostream & dumpOn( std::ostream & str ) const;
343     };
344
345     class MediaUnsupportedUrlSchemeException : public MediaBadUrlException
346     {
347     public:
348       MediaUnsupportedUrlSchemeException(const Url & url_r)
349       : MediaBadUrlException(url_r)
350       {}
351       virtual ~MediaUnsupportedUrlSchemeException() throw() {};
352     protected:
353       virtual std::ostream & dumpOn( std::ostream & str ) const;
354     };
355
356     class MediaNotSupportedException : public MediaException
357     {
358     public:
359       MediaNotSupportedException(const Url & url_r)
360       : MediaException()
361       , _url(url_r.asString())
362       {}
363       virtual ~MediaNotSupportedException() throw() {};
364     protected:
365       virtual std::ostream & dumpOn( std::ostream & str ) const;
366       std::string _url;
367     };
368
369     class MediaCurlException : public MediaException
370     {
371     public:
372       MediaCurlException(const Url & url_r,
373                          const std::string & err_r,
374                          const std::string & msg_r)
375       : MediaException()
376       , _url(url_r.asString())
377       , _err(err_r)
378       , _msg(msg_r)
379       {}
380       virtual ~MediaCurlException() throw() {};
381     protected:
382       virtual std::ostream & dumpOn( std::ostream & str ) const;
383       std::string _url;
384       std::string _err;
385       std::string _msg;
386     };
387
388     class MediaCurlSetOptException : public MediaException
389     {
390     public:
391       MediaCurlSetOptException(const Url & url_r, const std::string & msg_r)
392       : MediaException()
393       , _url(url_r.asString())
394       , _msg(msg_r)
395       {}
396       virtual ~MediaCurlSetOptException() throw() {};
397     protected:
398       virtual std::ostream & dumpOn( std::ostream & str ) const;
399       std::string _url;
400       std::string _msg;
401     };
402
403     class MediaMetalinkException : public MediaException
404     {
405     public:
406       MediaMetalinkException(const Url & url_r,
407                          const std::string & err_r,
408                          const std::string & msg_r)
409       : MediaException()
410       , _url(url_r.asString())
411       , _err(err_r)
412       , _msg(msg_r)
413       {}
414       virtual ~MediaMetalinkException() throw() {};
415     protected:
416       virtual std::ostream & dumpOn( std::ostream & str ) const;
417       std::string _url;
418       std::string _err;
419       std::string _msg;
420     };
421
422     class MediaMetalinkSetOptException : public MediaException
423     {
424     public:
425       MediaMetalinkSetOptException(const Url & url_r, const std::string & msg_r)
426       : MediaException()
427       , _url(url_r.asString())
428       , _msg(msg_r)
429       {}
430       virtual ~MediaMetalinkSetOptException() throw() {};
431     protected:
432       virtual std::ostream & dumpOn( std::ostream & str ) const;
433       std::string _url;
434       std::string _msg;
435     };
436
437     class MediaAria2cException : public MediaException
438     {
439     public:
440       MediaAria2cException(const Url & url_r,
441                          const std::string & err_r,
442                          const std::string & msg_r)
443       : MediaException()
444       , _url(url_r.asString())
445       , _err(err_r)
446       , _msg(msg_r)
447       {}
448       virtual ~MediaAria2cException() throw() {};
449     protected:
450       virtual std::ostream & dumpOn( std::ostream & str ) const;
451       std::string _url;
452       std::string _err;
453       std::string _msg;
454     };
455
456     class MediaAria2cSetOptException : public MediaException
457     {
458     public:
459       MediaAria2cSetOptException(const Url & url_r, const std::string & msg_r)
460       : MediaException()
461       , _url(url_r.asString())
462       , _msg(msg_r)
463       {}
464       virtual ~MediaAria2cSetOptException() throw() {};
465     protected:
466       virtual std::ostream & dumpOn( std::ostream & str ) const;
467       std::string _url;
468       std::string _msg;
469     };
470
471     class MediaNotDesiredException : public MediaException
472     {
473     public:
474       MediaNotDesiredException(const Url & url_r)
475       : MediaException()
476       , _url(url_r.asString())
477       {}
478       virtual ~MediaNotDesiredException() throw() {};
479     protected:
480       virtual std::ostream & dumpOn( std::ostream & str ) const;
481     private:
482       std::string  _url;
483     };
484
485     class MediaIsSharedException : public MediaException
486     {
487     public:
488       /**
489        * \param name A media source as string (see MediaSource class).
490        */
491       MediaIsSharedException(const std::string &name)
492       : MediaException()
493       , _name(name)
494       {}
495       virtual ~MediaIsSharedException() throw() {};
496     protected:
497       virtual std::ostream & dumpOn( std::ostream & str ) const;
498     private:
499       std::string _name;
500     };
501
502     class MediaNotEjectedException: public MediaException
503     {
504     public:
505       MediaNotEjectedException()
506       : MediaException("Can't eject any media")
507       , _name("")
508       {}
509
510       MediaNotEjectedException(const std::string &name)
511       : MediaException("Can't eject media")
512       , _name(name)
513       {}
514       virtual ~MediaNotEjectedException() throw() {};
515     protected:
516       virtual std::ostream & dumpOn( std::ostream & str ) const;
517     private:
518       std::string _name;
519     };
520
521     class MediaUnauthorizedException: public MediaException
522     {
523     public:
524       MediaUnauthorizedException()
525       : MediaException("Unauthorized media access")
526       , _url("")
527       , _err("")
528       , _hint("")
529       {}
530
531       MediaUnauthorizedException(const Url         &url_r,
532                                  const std::string &msg_r,
533                                  const std::string &err_r,
534                                  const std::string &hint_r)
535       : MediaException(msg_r)
536       , _url(url_r)
537       , _err(err_r)
538       , _hint(hint_r)
539       {}
540
541       virtual ~MediaUnauthorizedException() throw() {};
542
543       const Url         & url()  const { return _url;  }
544       const std::string & err()  const { return _err;  }
545       /** comma separated list of available authentication types */
546       const std::string & hint() const { return _hint; }
547
548     protected:
549       virtual std::ostream & dumpOn( std::ostream & str ) const;
550     private:
551       Url         _url;
552       std::string _err;
553       std::string _hint;
554     };
555
556     class MediaForbiddenException : public MediaException
557     {
558     public:
559       MediaForbiddenException(const Url & url_r, const std::string & msg = "")
560       : MediaException(msg)
561       , _url(url_r.asString()), _msg(msg)
562       {}
563       virtual ~MediaForbiddenException() throw() {};
564     protected:
565       virtual std::ostream & dumpOn( std::ostream & str ) const;
566       std::string _url;
567       std::string _msg;
568     };
569
570     class MediaTimeoutException : public MediaException
571     {
572     public:
573       MediaTimeoutException(const Url & url_r, const std::string & msg = "")
574       : MediaException(msg)
575       , _url(url_r.asString()), _msg(msg)
576       {}
577       virtual ~MediaTimeoutException() throw() {};
578     protected:
579       virtual std::ostream & dumpOn( std::ostream & str ) const;
580       std::string _url;
581       std::string _msg;
582     };
583
584     /** For HTTP 503 and similar. */
585     class MediaTemporaryProblemException : public MediaException
586     {
587     public:
588       MediaTemporaryProblemException(const Url & url_r, const std::string & msg = "")
589       : MediaException(msg)
590       , _url(url_r.asString()), _msg(msg)
591       {}
592       virtual ~MediaTemporaryProblemException() throw() {};
593     protected:
594       virtual std::ostream & dumpOn( std::ostream & str ) const;
595       std::string _url;
596       std::string _msg;
597     };
598
599     class MediaBadCAException : public MediaException
600     {
601     public:
602       MediaBadCAException(const Url & url_r, const std::string & msg = "")
603       : MediaException(msg)
604       , _url(url_r.asString()), _msg(msg)
605       {}
606       virtual ~MediaBadCAException() throw() {};
607     protected:
608       virtual std::ostream & dumpOn( std::ostream & str ) const;
609       std::string _url;
610       std::string _msg;
611     };
612
613     /**
614      * Thrown if /sbin/losetup fails to find an unused loop device for mounting
615      * an .iso image.
616      *
617      * UI hint: tell user to check permissions to read /dev/loop# or enablement
618      * of support for loop devices.
619      *
620      * \see MediaISO
621      */
622     class MediaNoLoopDeviceException : public MediaException
623     {
624     public:
625       MediaNoLoopDeviceException(const Url & url_r, const std::string & msg = "")
626         : MediaException(msg)
627         , _url(url_r.asString()), _msg(msg)
628       {}
629       virtual ~MediaNoLoopDeviceException() throw() {};
630     protected:
631       virtual std::ostream & dumpOn( std::ostream & str ) const;
632       std::string _url;
633       std::string _msg;
634     };
635   /////////////////////////////////////////////////////////////////
636   } // namespace media
637 } // namespace zypp
638 ///////////////////////////////////////////////////////////////////
639 #endif // ZYPP_MEDIA_MEDIAEXCEPTION_H