~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/code/errors.py

  • Committer: Francis J. Lacoste
  • Date: 2011-04-27 21:40:03 UTC
  • mto: This revision was merged to the branch mainline in revision 12971.
  • Revision ID: francis.lacoste@canonical.com-20110427214003-iiqhcyyswppyqjsx
Change the default timeout to production value, improved options documentation and use only one bin above timeout value.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
    'NoSuchBranch',
33
33
    'PrivateBranchRecipe',
34
34
    'ReviewNotPending',
35
 
    'StaleLastMirrored',
36
35
    'TooManyBuilds',
37
36
    'TooNewRecipeFormat',
38
37
    'UnknownBranchTypeError',
44
43
import httplib
45
44
 
46
45
from bzrlib.plugins.builder.recipe import RecipeParseError
47
 
from lazr.restful.declarations import error_status
 
46
from lazr.restful.declarations import (
 
47
    error_status,
 
48
    webservice_error,
 
49
    )
48
50
 
49
51
from lp.app.errors import NameLookupFailed
50
52
 
51
53
# Annotate the RecipeParseError's with a 400 webservice status.
52
 
error_status(httplib.BAD_REQUEST)(RecipeParseError)
 
54
error_status(400)(RecipeParseError)
53
55
 
54
56
 
55
57
class BadBranchMergeProposalSearchContext(Exception):
64
66
    """Base class for branch creation exceptions."""
65
67
 
66
68
 
67
 
@error_status(httplib.CONFLICT)
68
69
class BranchExists(BranchCreationException):
69
70
    """Raised when creating a branch that already exists."""
70
71
 
 
72
    webservice_error(400)
 
73
 
71
74
    def __init__(self, existing_branch):
72
75
        # XXX: TimPenhey 2009-07-12 bug=405214: This error
73
76
        # message logic is incorrect, but the exact text is being tested
91
94
    """Raised when there is an error determining a branch target."""
92
95
 
93
96
 
94
 
@error_status(httplib.BAD_REQUEST)
95
97
class CannotDeleteBranch(Exception):
96
98
    """The branch cannot be deleted at this time."""
 
99
    webservice_error(httplib.BAD_REQUEST)
97
100
 
98
101
 
99
102
class BranchCreationForbidden(BranchCreationException):
104
107
    """
105
108
 
106
109
 
107
 
@error_status(httplib.BAD_REQUEST)
108
110
class BranchCreatorNotMemberOfOwnerTeam(BranchCreationException):
109
111
    """Branch creator is not a member of the owner team.
110
112
 
112
114
    the branch to a team that they are not a member of.
113
115
    """
114
116
 
115
 
 
116
 
@error_status(httplib.BAD_REQUEST)
 
117
    webservice_error(400)
 
118
 
 
119
 
117
120
class BranchCreatorNotOwner(BranchCreationException):
118
121
    """A user cannot create a branch belonging to another user.
119
122
 
121
124
    the branch to another user.
122
125
    """
123
126
 
 
127
    webservice_error(400)
 
128
 
124
129
 
125
130
class BranchTypeError(Exception):
126
131
    """An operation cannot be performed for a particular branch type.
178
183
    """
179
184
 
180
185
 
181
 
@error_status(httplib.BAD_REQUEST)
182
186
class BranchMergeProposalExists(InvalidBranchMergeProposal):
183
187
    """Raised if there is already a matching BranchMergeProposal."""
184
188
 
185
 
    def __init__(self, existing_proposal):
186
 
        super(BranchMergeProposalExists, self).__init__(
187
 
                'There is already a branch merge proposal registered for '
188
 
                'branch %s to land on %s that is still active.' %
189
 
                (existing_proposal.source_branch.displayname,
190
 
                 existing_proposal.target_branch.displayname))
191
 
        self.existing_proposal = existing_proposal
 
189
    webservice_error(400) #Bad request.
192
190
 
193
191
 
194
192
class InvalidNamespace(Exception):
213
211
class NoSuchBranch(NameLookupFailed):
214
212
    """Raised when we try to load a branch that does not exist."""
215
213
 
 
214
    webservice_error(400)
 
215
 
216
216
    _message_prefix = "No such branch"
217
217
 
218
218
 
219
 
class StaleLastMirrored(Exception):
220
 
    """Raised when last_mirrored_id is out of date with on-disk value."""
221
 
 
222
 
    def __init__(self, db_branch, info):
223
 
        """Constructor.
224
 
 
225
 
        :param db_branch: The database branch.
226
 
        :param info: A dict of information about the branch, as produced by
227
 
            lp.codehosting.bzrutils.get_branch_info
228
 
        """
229
 
        self.db_branch = db_branch
230
 
        self.info = info
231
 
        Exception.__init__(
232
 
            self,
233
 
            'Database last_mirrored_id %s does not match on-disk value %s' %
234
 
            (db_branch.last_mirrored_id, self.info['last_revision_id']))
235
 
 
236
 
 
237
 
@error_status(httplib.BAD_REQUEST)
238
219
class PrivateBranchRecipe(Exception):
239
220
 
 
221
    webservice_error(400)
 
222
 
240
223
    def __init__(self, branch):
241
224
        message = (
242
225
            'Recipe may not refer to private branch: %s' %
270
253
    """Raised when the user specifies an unrecognized branch type."""
271
254
 
272
255
 
273
 
@error_status(httplib.BAD_REQUEST)
274
256
class CodeImportNotInReviewedState(Exception):
275
257
    """Raised when the user requests an import of a non-automatic import."""
276
258
 
 
259
    webservice_error(400)
 
260
 
277
261
 
278
262
class CodeImportAlreadyRequested(Exception):
279
263
    """Raised when the user requests an import that is already requested."""
283
267
        self.requesting_user = requesting_user
284
268
 
285
269
 
286
 
@error_status(httplib.BAD_REQUEST)
287
270
class CodeImportAlreadyRunning(Exception):
288
271
    """Raised when the user requests an import that is already running."""
289
272
 
290
 
 
291
 
@error_status(httplib.BAD_REQUEST)
 
273
    webservice_error(400)
 
274
 
 
275
 
292
276
class TooNewRecipeFormat(Exception):
293
277
    """The format of the recipe supplied was too new."""
294
278
 
 
279
    webservice_error(400)
 
280
 
295
281
    def __init__(self, supplied_format, newest_supported):
296
282
        super(TooNewRecipeFormat, self).__init__()
297
283
        self.supplied_format = supplied_format
298
284
        self.newest_supported = newest_supported
299
285
 
300
286
 
301
 
@error_status(httplib.BAD_REQUEST)
302
287
class RecipeBuildException(Exception):
303
288
 
 
289
    webservice_error(400)
 
290
 
304
291
    def __init__(self, recipe, distroseries, template):
305
292
        self.recipe = recipe
306
293
        self.distroseries = distroseries
336
323
            'A build against this distro is not allowed.')
337
324
 
338
325
 
339
 
@error_status(httplib.BAD_REQUEST)
340
326
class InvalidMergeQueueConfig(Exception):
341
327
    """The config specified is not a valid JSON string."""
342
328
 
 
329
    webservice_error(400)
 
330
 
343
331
    def __init__(self):
344
332
        message = ('The configuration specified is not a valid JSON string.')
345
333
        Exception.__init__(self, message)