~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: Aaron Bentley
  • Date: 2007-02-07 03:09:58 UTC
  • mfrom: (2268 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2269.
  • Revision ID: aaron.bentley@utoronto.ca-20070207030958-fx6ykp7rg7zma6xu
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""
19
19
 
20
20
 
21
 
from bzrlib import symbol_versioning
22
 
from bzrlib.patches import (PatchSyntax, 
23
 
                            PatchConflict, 
24
 
                            MalformedPatchHeader,
25
 
                            MalformedHunkHeader,
26
 
                            MalformedLine,)
 
21
from bzrlib import (
 
22
    osutils,
 
23
    symbol_versioning,
 
24
    )
 
25
from bzrlib.patches import (
 
26
    MalformedHunkHeader,
 
27
    MalformedLine,
 
28
    MalformedPatchHeader,
 
29
    PatchConflict,
 
30
    PatchSyntax,
 
31
    )
27
32
 
28
33
 
29
34
# TODO: is there any value in providing the .args field used by standard
199
204
        self.revision_id = revision_id
200
205
        self.branch = branch
201
206
 
 
207
class ReservedId(BzrError):
 
208
 
 
209
    _fmt = "Reserved revision-id {%(revision_id)s}"
 
210
 
 
211
    def __init__(self, revision_id):
 
212
        self.revision_id = revision_id
202
213
 
203
214
class NoSuchId(BzrError):
204
215
 
327
338
    _fmt = "File exists: %(path)r%(extra)s"
328
339
 
329
340
 
 
341
class RenameFailedFilesExist(BzrError):
 
342
    """Used when renaming and both source and dest exist."""
 
343
 
 
344
    _fmt = ("Could not rename %(source)s => %(dest)s because both files exist."
 
345
         "%(extra)s")
 
346
 
 
347
    def __init__(self, source, dest, extra=None):
 
348
        BzrError.__init__(self)
 
349
        self.source = str(source)
 
350
        self.dest = str(dest)
 
351
        if extra:
 
352
            self.extra = ' ' + str(extra)
 
353
        else:
 
354
            self.extra = ''
 
355
 
 
356
 
 
357
class NotADirectory(PathError):
 
358
 
 
359
    _fmt = "%(path)r is not a directory %(extra)s"
 
360
 
 
361
 
 
362
class NotInWorkingDirectory(PathError):
 
363
 
 
364
    _fmt = "%(path)r is not in the working directory %(extra)s"
 
365
 
 
366
 
330
367
class DirectoryNotEmpty(PathError):
331
368
 
332
369
    _fmt = "Directory not empty: %(path)r%(extra)s"
368
405
        self.args = [base] + list(args)
369
406
 
370
407
 
 
408
class UnknownHook(BzrError):
 
409
 
 
410
    _fmt = "The %(type)s hook '%(hook)s' is unknown in this version of bzrlib."
 
411
 
 
412
    def __init__(self, hook_type, hook_name):
 
413
        BzrError.__init__(self)
 
414
        self.type = hook_type
 
415
        self.hook = hook_name
 
416
 
 
417
 
371
418
class UnsupportedProtocol(PathError):
372
419
 
373
420
    _fmt = 'Unsupported protocol for url "%(path)s"%(extra)s'
499
546
        self.repo_format = repo_format
500
547
 
501
548
 
 
549
class AlreadyVersionedError(BzrError):
 
550
    """Used when a path is expected not to be versioned, but it is."""
 
551
 
 
552
    _fmt = "%(context_info)s%(path)s is already versioned"
 
553
 
 
554
    def __init__(self, path, context_info=None):
 
555
        """Construct a new NotVersionedError.
 
556
 
 
557
        :param path: This is the path which is versioned,
 
558
        which should be in a user friendly form.
 
559
        :param context_info: If given, this is information about the context,
 
560
        which could explain why this is expected to not be versioned.
 
561
        """
 
562
        BzrError.__init__(self)
 
563
        self.path = path
 
564
        if context_info is None:
 
565
            self.context_info = ''
 
566
        else:
 
567
            self.context_info = context_info + ". "
 
568
 
 
569
 
502
570
class NotVersionedError(BzrError):
503
 
 
504
 
    _fmt = "%(path)s is not versioned"
505
 
 
506
 
    def __init__(self, path):
 
571
    """Used when a path is expected to be versioned, but it is not."""
 
572
 
 
573
    _fmt = "%(context_info)s%(path)s is not versioned"
 
574
 
 
575
    def __init__(self, path, context_info=None):
 
576
        """Construct a new NotVersionedError.
 
577
 
 
578
        :param path: This is the path which is not versioned,
 
579
        which should be in a user friendly form.
 
580
        :param context_info: If given, this is information about the context,
 
581
        which could explain why this is expected to be versioned.
 
582
        """
507
583
        BzrError.__init__(self)
508
584
        self.path = path
 
585
        if context_info is None:
 
586
            self.context_info = ''
 
587
        else:
 
588
            self.context_info = context_info + ". "
509
589
 
510
590
 
511
591
class PathsNotVersionedError(BzrError):
512
 
    # used when reporting several paths are not versioned
 
592
    """Used when reporting several paths which are not versioned"""
513
593
 
514
594
    _fmt = "Path(s) are not versioned: %(paths_as_string)s"
515
595
 
522
602
 
523
603
class PathsDoNotExist(BzrError):
524
604
 
525
 
    _fmt = "Path(s) do not exist: %(paths_as_string)s"
 
605
    _fmt = "Path(s) do not exist: %(paths_as_string)s%(extra)s"
526
606
 
527
607
    # used when reporting that paths are neither versioned nor in the working
528
608
    # tree
529
609
 
530
 
    def __init__(self, paths):
 
610
    def __init__(self, paths, extra=None):
531
611
        # circular import
532
612
        from bzrlib.osutils import quotefn
533
613
        BzrError.__init__(self)
534
614
        self.paths = paths
535
615
        self.paths_as_string = ' '.join([quotefn(p) for p in paths])
 
616
        if extra:
 
617
            self.extra = ': ' + str(extra)
 
618
        else:
 
619
            self.extra = ''
536
620
 
537
621
 
538
622
class BadFileKindError(BzrError):
1286
1370
    _fmt = "Moving the root directory is not supported at this time"
1287
1371
 
1288
1372
 
 
1373
class BzrMoveFailedError(BzrError):
 
1374
 
 
1375
    _fmt = "Could not move %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
1376
 
 
1377
    def __init__(self, from_path='', to_path='', extra=None):
 
1378
        BzrError.__init__(self)
 
1379
        if extra:
 
1380
            self.extra = ': ' + str(extra)
 
1381
        else:
 
1382
            self.extra = ''
 
1383
 
 
1384
        has_from = len(from_path) > 0
 
1385
        has_to = len(to_path) > 0
 
1386
        if has_from:
 
1387
            self.from_path = osutils.splitpath(from_path)[-1]
 
1388
        else:
 
1389
            self.from_path = ''
 
1390
 
 
1391
        if has_to:
 
1392
            self.to_path = osutils.splitpath(to_path)[-1]
 
1393
        else:
 
1394
            self.to_path = ''
 
1395
 
 
1396
        self.operator = ""
 
1397
        if has_from and has_to:
 
1398
            self.operator = " =>"
 
1399
        elif has_from:
 
1400
            self.from_path = "from " + from_path
 
1401
        elif has_to:
 
1402
            self.operator = "to"
 
1403
        else:
 
1404
            self.operator = "file"
 
1405
 
 
1406
 
 
1407
class BzrRenameFailedError(BzrMoveFailedError):
 
1408
 
 
1409
    _fmt = "Could not rename %(from_path)s%(operator)s %(to_path)s%(extra)s"
 
1410
 
 
1411
    def __init__(self, from_path, to_path, extra=None):
 
1412
        BzrMoveFailedError.__init__(self, from_path, to_path, extra)
 
1413
 
 
1414
 
1289
1415
class BzrBadParameterNotString(BzrBadParameter):
1290
1416
 
1291
1417
    _fmt = "Parameter %(param)s is not a string or unicode string."
1551
1677
class NoSmartMedium(BzrError):
1552
1678
 
1553
1679
    _fmt = "The transport '%(transport)s' cannot tunnel the smart protocol."
 
1680
    internal_error = True
1554
1681
 
1555
1682
    def __init__(self, transport):
1556
1683
        self.transport = transport