Imported Upstream version 16.3.2
[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 MediaSystemException : public MediaException
218     {
219     public:
220       MediaSystemException(const Url & url_r,
221                            const std::string & message_r)
222       : MediaException()
223       , _url(url_r.asString())
224       , _message(message_r)
225       {}
226       virtual ~MediaSystemException() throw() {};
227     protected:
228       virtual std::ostream & dumpOn( std::ostream & str ) const;
229     private:
230       std::string _url;
231       std::string _message;
232     };
233
234     class MediaNotAFileException : public MediaException
235     {
236     public:
237       MediaNotAFileException(const Url & url_r,
238                              const Pathname & path_r)
239       : MediaException()
240       , _url(url_r.asString())
241       , _path(path_r.asString())
242       {}
243       virtual ~MediaNotAFileException() throw() {};
244     protected:
245       virtual std::ostream & dumpOn( std::ostream & str ) const;
246     private:
247       std::string _url;
248       std::string _path;
249     };
250
251     class MediaNotADirException : public MediaException
252     {
253     public:
254       MediaNotADirException(const Url & url_r,
255                             const Pathname & path_r)
256       : MediaException()
257       , _url(url_r.asString())
258       , _path(path_r.asString())
259       {}
260       virtual ~MediaNotADirException() throw() {};
261     protected:
262       virtual std::ostream & dumpOn( std::ostream & str ) const;
263     private:
264       std::string _url;
265       std::string _path;
266     };
267
268     class MediaBadUrlException : public MediaException
269     {
270     public:
271       MediaBadUrlException(const Url & url_r,
272                            const std::string &msg_r = std::string())
273       : MediaException()
274       , _url(url_r.asString())
275       , _msg(msg_r)
276       {}
277       virtual ~MediaBadUrlException() throw() {};
278     protected:
279       virtual std::ostream & dumpOn( std::ostream & str ) const;
280       std::string _url;
281       std::string _msg;
282     };
283
284     class MediaBadUrlEmptyHostException : public MediaBadUrlException
285     {
286     public:
287       MediaBadUrlEmptyHostException(const Url & url_r)
288       : MediaBadUrlException(url_r)
289       {}
290       virtual ~MediaBadUrlEmptyHostException() throw() {};
291     protected:
292       virtual std::ostream & dumpOn( std::ostream & str ) const;
293     };
294
295     class MediaBadUrlEmptyFilesystemException : public MediaBadUrlException
296     {
297     public:
298       MediaBadUrlEmptyFilesystemException(const Url & url_r)
299       : MediaBadUrlException(url_r)
300       {}
301       virtual ~MediaBadUrlEmptyFilesystemException() throw() {};
302     protected:
303       virtual std::ostream & dumpOn( std::ostream & str ) const;
304     };
305
306     class MediaBadUrlEmptyDestinationException : public MediaBadUrlException
307     {
308     public:
309       MediaBadUrlEmptyDestinationException(const Url & url_r)
310       : MediaBadUrlException(url_r)
311       {}
312       virtual ~MediaBadUrlEmptyDestinationException() throw() {};
313     protected:
314       virtual std::ostream & dumpOn( std::ostream & str ) const;
315     };
316
317     class MediaUnsupportedUrlSchemeException : public MediaBadUrlException
318     {
319     public:
320       MediaUnsupportedUrlSchemeException(const Url & url_r)
321       : MediaBadUrlException(url_r)
322       {}
323       virtual ~MediaUnsupportedUrlSchemeException() throw() {};
324     protected:
325       virtual std::ostream & dumpOn( std::ostream & str ) const;
326     };
327
328     class MediaNotSupportedException : public MediaException
329     {
330     public:
331       MediaNotSupportedException(const Url & url_r)
332       : MediaException()
333       , _url(url_r.asString())
334       {}
335       virtual ~MediaNotSupportedException() throw() {};
336     protected:
337       virtual std::ostream & dumpOn( std::ostream & str ) const;
338       std::string _url;
339     };
340
341     class MediaCurlException : public MediaException
342     {
343     public:
344       MediaCurlException(const Url & url_r,
345                          const std::string & err_r,
346                          const std::string & msg_r)
347       : MediaException()
348       , _url(url_r.asString())
349       , _err(err_r)
350       , _msg(msg_r)
351       {}
352       virtual ~MediaCurlException() throw() {};
353       std::string errstr() const { return _err; }
354     protected:
355       virtual std::ostream & dumpOn( std::ostream & str ) const;
356       std::string _url;
357       std::string _err;
358       std::string _msg;
359     };
360
361     class MediaCurlSetOptException : public MediaException
362     {
363     public:
364       MediaCurlSetOptException(const Url & url_r, const std::string & msg_r)
365       : MediaException()
366       , _url(url_r.asString())
367       , _msg(msg_r)
368       {}
369       virtual ~MediaCurlSetOptException() throw() {};
370     protected:
371       virtual std::ostream & dumpOn( std::ostream & str ) const;
372       std::string _url;
373       std::string _msg;
374     };
375
376     class MediaNotDesiredException : public MediaException
377     {
378     public:
379       MediaNotDesiredException(const Url & url_r)
380       : MediaException()
381       , _url(url_r.asString())
382       {}
383       virtual ~MediaNotDesiredException() throw() {};
384     protected:
385       virtual std::ostream & dumpOn( std::ostream & str ) const;
386     private:
387       std::string  _url;
388     };
389
390     class MediaIsSharedException : public MediaException
391     {
392     public:
393       /**
394        * \param name A media source as string (see MediaSource class).
395        */
396       MediaIsSharedException(const std::string &name)
397       : MediaException()
398       , _name(name)
399       {}
400       virtual ~MediaIsSharedException() throw() {};
401     protected:
402       virtual std::ostream & dumpOn( std::ostream & str ) const;
403     private:
404       std::string _name;
405     };
406
407     class MediaNotEjectedException: public MediaException
408     {
409     public:
410       MediaNotEjectedException()
411       : MediaException("Can't eject any media")
412       , _name("")
413       {}
414
415       MediaNotEjectedException(const std::string &name)
416       : MediaException("Can't eject media")
417       , _name(name)
418       {}
419       virtual ~MediaNotEjectedException() throw() {};
420     protected:
421       virtual std::ostream & dumpOn( std::ostream & str ) const;
422     private:
423       std::string _name;
424     };
425
426     class MediaUnauthorizedException: public MediaException
427     {
428     public:
429       MediaUnauthorizedException()
430       : MediaException("Unauthorized media access")
431       , _url("")
432       , _err("")
433       , _hint("")
434       {}
435
436       MediaUnauthorizedException(const Url         &url_r,
437                                  const std::string &msg_r,
438                                  const std::string &err_r,
439                                  const std::string &hint_r)
440       : MediaException(msg_r)
441       , _url(url_r)
442       , _err(err_r)
443       , _hint(hint_r)
444       {}
445
446       virtual ~MediaUnauthorizedException() throw() {};
447
448       const Url         & url()  const { return _url;  }
449       const std::string & err()  const { return _err;  }
450       /** comma separated list of available authentication types */
451       const std::string & hint() const { return _hint; }
452
453     protected:
454       virtual std::ostream & dumpOn( std::ostream & str ) const;
455     private:
456       Url         _url;
457       std::string _err;
458       std::string _hint;
459     };
460
461     class MediaForbiddenException : public MediaException
462     {
463     public:
464       MediaForbiddenException(const Url & url_r, const std::string & msg = "")
465       : MediaException(msg)
466       , _url(url_r.asString()), _msg(msg)
467       {}
468       virtual ~MediaForbiddenException() throw() {};
469     protected:
470       virtual std::ostream & dumpOn( std::ostream & str ) const;
471       std::string _url;
472       std::string _msg;
473     };
474
475     class MediaTimeoutException : public MediaException
476     {
477     public:
478       MediaTimeoutException(const Url & url_r, const std::string & msg = "")
479       : MediaException(msg)
480       , _url(url_r.asString()), _msg(msg)
481       {}
482       virtual ~MediaTimeoutException() throw() {};
483     protected:
484       virtual std::ostream & dumpOn( std::ostream & str ) const;
485       std::string _url;
486       std::string _msg;
487     };
488
489     /** For HTTP 503 and similar. */
490     class MediaTemporaryProblemException : public MediaException
491     {
492     public:
493       MediaTemporaryProblemException(const Url & url_r, const std::string & msg = "")
494       : MediaException(msg)
495       , _url(url_r.asString()), _msg(msg)
496       {}
497       virtual ~MediaTemporaryProblemException() throw() {};
498     protected:
499       virtual std::ostream & dumpOn( std::ostream & str ) const;
500       std::string _url;
501       std::string _msg;
502     };
503
504     class MediaBadCAException : public MediaException
505     {
506     public:
507       MediaBadCAException(const Url & url_r, const std::string & msg = "")
508       : MediaException(msg)
509       , _url(url_r.asString()), _msg(msg)
510       {}
511       virtual ~MediaBadCAException() throw() {};
512     protected:
513       virtual std::ostream & dumpOn( std::ostream & str ) const;
514       std::string _url;
515       std::string _msg;
516     };
517
518     /**
519      * Thrown if /sbin/losetup fails to find an unused loop device for mounting
520      * an .iso image.
521      *
522      * UI hint: tell user to check permissions to read /dev/loop# or enablement
523      * of support for loop devices.
524      *
525      * \see MediaISO
526      */
527     class MediaNoLoopDeviceException : public MediaException
528     {
529     public:
530       MediaNoLoopDeviceException(const Url & url_r, const std::string & msg = "")
531         : MediaException(msg)
532         , _url(url_r.asString()), _msg(msg)
533       {}
534       virtual ~MediaNoLoopDeviceException() throw() {};
535     protected:
536       virtual std::ostream & dumpOn( std::ostream & str ) const;
537       std::string _url;
538       std::string _msg;
539     };
540   /////////////////////////////////////////////////////////////////
541   } // namespace media
542 } // namespace zypp
543 ///////////////////////////////////////////////////////////////////
544 #endif // ZYPP_MEDIA_MEDIAEXCEPTION_H