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