Converting multi-line-string-comment to a real comment.
[mediagoblin.git] / mediagoblin / process_media / errors.py
CommitLineData
4b860cb8
CAW
1# GNU MediaGoblin -- federated, autonomous media hosting
2# Copyright (C) 2011 Free Software Foundation, Inc
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Affero General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17from mediagoblin.util import lazy_pass_to_ugettext as _
18
19class BaseProcessingFail(Exception):
20 """
21 Base exception that all other processing failure messages should
22 subclass from.
23
24 You shouldn't call this itself; instead you should subclass it
25 and provid the exception_path and general_message applicable to
26 this error.
27 """
28 general_message = u''
29
30 @property
31 def exception_path(self):
32 return u"%s.%s" % (
33 self.__class__.__module__, self.__class__.__name__)
34
35 def __init__(self, **metadata):
36 self.metadata = metadata or {}
37
38 def generate_error_message(self):
39 """
40 Generate an error to display to users in the panel.
41
42 Uses this class's general_message, possibly interpolated
43 with any metadata in self.metadata['error_message_vars'],
44 if appropriate.
45 """
46 return self.general_message % self.metadata.get('error_message_vars', {})
47
48
49class BadMediaFail(BaseProcessingFail):
50 """
51 Error that should be raised when an inappropriate file was given
52 for the media type specified.
53 """
54 general_message = _(u'Invalid file given for media type.')