Show More
@@ -1,114 +1,116 | |||||
1 | # error.py - Mercurial exceptions |
|
1 | # error.py - Mercurial exceptions | |
2 | # |
|
2 | # | |
3 | # Copyright 2005-2008 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005-2008 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | """Mercurial exceptions. |
|
8 | """Mercurial exceptions. | |
9 |
|
9 | |||
10 | This allows us to catch exceptions at higher levels without forcing |
|
10 | This allows us to catch exceptions at higher levels without forcing | |
11 | imports. |
|
11 | imports. | |
12 | """ |
|
12 | """ | |
13 |
|
13 | |||
14 | # Do not import anything here, please |
|
14 | # Do not import anything here, please | |
15 |
|
15 | |||
16 | class RevlogError(Exception): |
|
16 | class RevlogError(Exception): | |
17 | pass |
|
17 | pass | |
18 |
|
18 | |||
19 | class LookupError(RevlogError, KeyError): |
|
19 | class LookupError(RevlogError, KeyError): | |
20 | def __init__(self, name, index, message): |
|
20 | def __init__(self, name, index, message): | |
21 | self.name = name |
|
21 | self.name = name | |
22 | if isinstance(name, str) and len(name) == 20: |
|
22 | if isinstance(name, str) and len(name) == 20: | |
23 | from node import short |
|
23 | from node import short | |
24 | name = short(name) |
|
24 | name = short(name) | |
25 | RevlogError.__init__(self, '%s@%s: %s' % (index, name, message)) |
|
25 | RevlogError.__init__(self, '%s@%s: %s' % (index, name, message)) | |
26 |
|
26 | |||
27 | def __str__(self): |
|
27 | def __str__(self): | |
28 | return RevlogError.__str__(self) |
|
28 | return RevlogError.__str__(self) | |
29 |
|
29 | |||
30 | class ManifestLookupError(LookupError): |
|
30 | class ManifestLookupError(LookupError): | |
31 | pass |
|
31 | pass | |
32 |
|
32 | |||
33 | class CommandError(Exception): |
|
33 | class CommandError(Exception): | |
34 | """Exception raised on errors in parsing the command line.""" |
|
34 | """Exception raised on errors in parsing the command line.""" | |
35 |
|
35 | |||
36 | class InterventionRequired(Exception): |
|
36 | class InterventionRequired(Exception): | |
37 | """Exception raised when a command requires human intervention.""" |
|
37 | """Exception raised when a command requires human intervention.""" | |
38 |
|
38 | |||
39 | class Abort(Exception): |
|
39 | class Abort(Exception): | |
40 | """Raised if a command needs to print an error and exit.""" |
|
40 | """Raised if a command needs to print an error and exit.""" | |
41 | def __init__(self, *args, **kw): |
|
41 | def __init__(self, *args, **kw): | |
42 | Exception.__init__(self, *args) |
|
42 | Exception.__init__(self, *args) | |
43 | self.hint = kw.get('hint') |
|
43 | self.hint = kw.get('hint') | |
44 |
|
44 | |||
45 | class ConfigError(Abort): |
|
45 | class ConfigError(Abort): | |
46 | 'Exception raised when parsing config files' |
|
46 | 'Exception raised when parsing config files' | |
47 |
|
47 | |||
48 | class OutOfBandError(Exception): |
|
48 | class OutOfBandError(Exception): | |
49 | 'Exception raised when a remote repo reports failure' |
|
49 | 'Exception raised when a remote repo reports failure' | |
50 |
|
50 | |||
51 | class ParseError(Exception): |
|
51 | class ParseError(Exception): | |
52 | 'Exception raised when parsing config files (msg[, pos])' |
|
52 | 'Exception raised when parsing config files (msg[, pos])' | |
53 |
|
53 | |||
54 | class RepoError(Exception): |
|
54 | class RepoError(Exception): | |
55 | def __init__(self, *args, **kw): |
|
55 | def __init__(self, *args, **kw): | |
56 | Exception.__init__(self, *args) |
|
56 | Exception.__init__(self, *args) | |
57 | self.hint = kw.get('hint') |
|
57 | self.hint = kw.get('hint') | |
58 |
|
58 | |||
59 | class RepoLookupError(RepoError): |
|
59 | class RepoLookupError(RepoError): | |
60 | pass |
|
60 | pass | |
61 |
|
61 | |||
62 | class CapabilityError(RepoError): |
|
62 | class CapabilityError(RepoError): | |
63 | pass |
|
63 | pass | |
64 |
|
64 | |||
65 | class RequirementError(RepoError): |
|
65 | class RequirementError(RepoError): | |
66 | """Exception raised if .hg/requires has an unknown entry.""" |
|
66 | """Exception raised if .hg/requires has an unknown entry.""" | |
67 | pass |
|
67 | pass | |
68 |
|
68 | |||
69 | class LockError(IOError): |
|
69 | class LockError(IOError): | |
70 | def __init__(self, errno, strerror, filename, desc): |
|
70 | def __init__(self, errno, strerror, filename, desc): | |
71 | IOError.__init__(self, errno, strerror, filename) |
|
71 | IOError.__init__(self, errno, strerror, filename) | |
72 | self.desc = desc |
|
72 | self.desc = desc | |
73 |
|
73 | |||
74 | class LockHeld(LockError): |
|
74 | class LockHeld(LockError): | |
75 | def __init__(self, errno, filename, desc, locker): |
|
75 | def __init__(self, errno, filename, desc, locker): | |
76 | LockError.__init__(self, errno, 'Lock held', filename, desc) |
|
76 | LockError.__init__(self, errno, 'Lock held', filename, desc) | |
77 | self.locker = locker |
|
77 | self.locker = locker | |
78 |
|
78 | |||
79 | class LockUnavailable(LockError): |
|
79 | class LockUnavailable(LockError): | |
80 | pass |
|
80 | pass | |
81 |
|
81 | |||
82 | class ResponseError(Exception): |
|
82 | class ResponseError(Exception): | |
83 | """Raised to print an error with part of output and exit.""" |
|
83 | """Raised to print an error with part of output and exit.""" | |
84 |
|
84 | |||
85 | class UnknownCommand(Exception): |
|
85 | class UnknownCommand(Exception): | |
86 | """Exception raised if command is not in the command table.""" |
|
86 | """Exception raised if command is not in the command table.""" | |
87 |
|
87 | |||
88 | class AmbiguousCommand(Exception): |
|
88 | class AmbiguousCommand(Exception): | |
89 | """Exception raised if command shortcut matches more than one command.""" |
|
89 | """Exception raised if command shortcut matches more than one command.""" | |
90 |
|
90 | |||
91 | # derived from KeyboardInterrupt to simplify some breakout code |
|
91 | # derived from KeyboardInterrupt to simplify some breakout code | |
92 | class SignalInterrupt(KeyboardInterrupt): |
|
92 | class SignalInterrupt(KeyboardInterrupt): | |
93 | """Exception raised on SIGTERM and SIGHUP.""" |
|
93 | """Exception raised on SIGTERM and SIGHUP.""" | |
94 |
|
94 | |||
95 | class SignatureError(Exception): |
|
95 | class SignatureError(Exception): | |
96 | pass |
|
96 | pass | |
97 |
|
97 | |||
98 | class PushRaced(RuntimeError): |
|
98 | class PushRaced(RuntimeError): | |
99 | """An exception raised during unbundling that indicate a push race""" |
|
99 | """An exception raised during unbundling that indicate a push race""" | |
100 |
|
100 | |||
101 | # bundle2 related errors |
|
101 | # bundle2 related errors | |
102 | class BundleValueError(ValueError): |
|
102 | class BundleValueError(ValueError): | |
103 | """error raised when bundle2 cannot be processed |
|
103 | """error raised when bundle2 cannot be processed""" | |
104 |
|
||||
105 | Current main usecase is unsupported part types.""" |
|
|||
106 |
|
104 | |||
107 | def __init__(self, parttype): |
|
105 | def __init__(self, parttype, params=()): | |
108 | self.parttype = parttype |
|
106 | self.parttype = parttype | |
109 | super(BundleValueError, self).__init__(parttype) |
|
107 | self.params = params | |
|
108 | msg = parttype | |||
|
109 | if self.params: | |||
|
110 | msg = '%s - %s' % (msg, ', '.join(self.params)) | |||
|
111 | super(BundleValueError, self).__init__(msg) | |||
110 |
|
112 | |||
111 | class ReadOnlyPartError(RuntimeError): |
|
113 | class ReadOnlyPartError(RuntimeError): | |
112 | """error raised when code tries to alter a part being generated""" |
|
114 | """error raised when code tries to alter a part being generated""" | |
113 | pass |
|
115 | pass | |
114 |
|
116 |
General Comments 0
You need to be logged in to leave comments.
Login now