mercurial/error.py
author Pascal Quantin <pascal.quantin@gmail.com>
Mon, 23 Mar 2009 10:48:45 +0100
changeset 7867 01bd0efef1b5
parent 7646 e62a456b8dc5
child 7947 a454eeb1b827
permissions -rw-r--r--
merge tools: fix typo in Beyond Compare's 3 command line Fix a typo error preventing 'base' to be displayed properly.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7633
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     1
"""
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     2
error.py - Mercurial exceptions
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     3
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     4
This allows us to catch exceptions at higher levels without forcing imports
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     5
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     6
Copyright 2005-2008 Matt Mackall <mpm@selenic.com>
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     7
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     8
This software may be used and distributed according to the terms
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     9
of the GNU General Public License, incorporated herein by reference.
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    10
"""
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    11
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    12
# Do not import anything here, please
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    13
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    14
class RevlogError(Exception):
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    15
    pass
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    16
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    17
class LookupError(RevlogError, KeyError):
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    18
    def __init__(self, name, index, message):
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    19
        self.name = name
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    20
        if isinstance(name, str) and len(name) == 20:
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    21
            from node import short
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    22
            name = short(name)
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    23
        RevlogError.__init__(self, '%s@%s: %s' % (index, name, message))
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    24
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    25
    def __str__(self):
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    26
        return RevlogError.__str__(self)
7636
e3f8c6d6b72e error: move ParseError
Matt Mackall <mpm@selenic.com>
parents: 7633
diff changeset
    27
e3f8c6d6b72e error: move ParseError
Matt Mackall <mpm@selenic.com>
parents: 7633
diff changeset
    28
class ParseError(Exception):
e3f8c6d6b72e error: move ParseError
Matt Mackall <mpm@selenic.com>
parents: 7633
diff changeset
    29
    """Exception raised on errors in parsing the command line."""
7637
1d54e2f6c0b7 error: move repo errors
Matt Mackall <mpm@selenic.com>
parents: 7636
diff changeset
    30
1d54e2f6c0b7 error: move repo errors
Matt Mackall <mpm@selenic.com>
parents: 7636
diff changeset
    31
class RepoError(Exception):
1d54e2f6c0b7 error: move repo errors
Matt Mackall <mpm@selenic.com>
parents: 7636
diff changeset
    32
    pass
1d54e2f6c0b7 error: move repo errors
Matt Mackall <mpm@selenic.com>
parents: 7636
diff changeset
    33
1d54e2f6c0b7 error: move repo errors
Matt Mackall <mpm@selenic.com>
parents: 7636
diff changeset
    34
class CapabilityError(RepoError):
1d54e2f6c0b7 error: move repo errors
Matt Mackall <mpm@selenic.com>
parents: 7636
diff changeset
    35
    pass
7640
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
    36
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
    37
class LockError(IOError):
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
    38
    def __init__(self, errno, strerror, filename, desc):
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
    39
        IOError.__init__(self, errno, strerror, filename)
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
    40
        self.desc = desc
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
    41
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
    42
class LockHeld(LockError):
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
    43
    def __init__(self, errno, filename, desc, locker):
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
    44
        LockError.__init__(self, errno, 'Lock held', filename, desc)
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
    45
        self.locker = locker
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
    46
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
    47
class LockUnavailable(LockError):
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
    48
    pass
7641
d2f753830f80 error: move UnexpectedOutput (now ResponseError)
Matt Mackall <mpm@selenic.com>
parents: 7640
diff changeset
    49
d2f753830f80 error: move UnexpectedOutput (now ResponseError)
Matt Mackall <mpm@selenic.com>
parents: 7640
diff changeset
    50
class ResponseError(Exception):
d2f753830f80 error: move UnexpectedOutput (now ResponseError)
Matt Mackall <mpm@selenic.com>
parents: 7640
diff changeset
    51
    """Raised to print an error with part of output and exit."""
d2f753830f80 error: move UnexpectedOutput (now ResponseError)
Matt Mackall <mpm@selenic.com>
parents: 7640
diff changeset
    52
7643
9a1ea6587557 error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
    53
class UnknownCommand(Exception):
9a1ea6587557 error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
    54
    """Exception raised if command is not in the command table."""
9a1ea6587557 error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
    55
9a1ea6587557 error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
    56
class AmbiguousCommand(Exception):
9a1ea6587557 error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
    57
    """Exception raised if command shortcut matches more than one command."""
9a1ea6587557 error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
    58
7644
182b7114d35a error: move SignalInterrupt
Matt Mackall <mpm@selenic.com>
parents: 7643
diff changeset
    59
# derived from KeyboardInterrupt to simplify some breakout code
182b7114d35a error: move SignalInterrupt
Matt Mackall <mpm@selenic.com>
parents: 7643
diff changeset
    60
class SignalInterrupt(KeyboardInterrupt):
182b7114d35a error: move SignalInterrupt
Matt Mackall <mpm@selenic.com>
parents: 7643
diff changeset
    61
    """Exception raised on SIGTERM and SIGHUP."""
7646
e62a456b8dc5 error: move SignatureError
Matt Mackall <mpm@selenic.com>
parents: 7644
diff changeset
    62
e62a456b8dc5 error: move SignatureError
Matt Mackall <mpm@selenic.com>
parents: 7644
diff changeset
    63
class SignatureError(Exception):
e62a456b8dc5 error: move SignatureError
Matt Mackall <mpm@selenic.com>
parents: 7644
diff changeset
    64
    pass