Show More
@@ -51,6 +51,39 b' class Hint(object):' | |||
|
51 | 51 | super(Hint, self).__init__(*args, **kw) |
|
52 | 52 | |
|
53 | 53 | |
|
54 | class Abort(Hint, Exception): | |
|
55 | """Raised if a command needs to print an error and exit.""" | |
|
56 | ||
|
57 | def __init__(self, message, hint=None, detailed_exit_code=None): | |
|
58 | # type: (bytes, Optional[bytes]) -> None | |
|
59 | self.message = message | |
|
60 | self.hint = hint | |
|
61 | self.detailed_exit_code = detailed_exit_code | |
|
62 | # Pass the message into the Exception constructor to help extensions | |
|
63 | # that look for exc.args[0]. | |
|
64 | Exception.__init__(self, message) | |
|
65 | ||
|
66 | def __bytes__(self): | |
|
67 | return self.message | |
|
68 | ||
|
69 | if pycompat.ispy3: | |
|
70 | ||
|
71 | def __str__(self): | |
|
72 | # the output would be unreadable if the message was translated, | |
|
73 | # but do not replace it with encoding.strfromlocal(), which | |
|
74 | # may raise another exception. | |
|
75 | return pycompat.sysstr(self.__bytes__()) | |
|
76 | ||
|
77 | def format(self): | |
|
78 | # type: () -> bytes | |
|
79 | from .i18n import _ | |
|
80 | ||
|
81 | message = _(b"abort: %s\n") % self.message | |
|
82 | if self.hint: | |
|
83 | message += _(b"(%s)\n") % self.hint | |
|
84 | return message | |
|
85 | ||
|
86 | ||
|
54 | 87 | class StorageError(Hint, Exception): |
|
55 | 88 | """Raised when an error occurs in a storage layer. |
|
56 | 89 | |
@@ -182,39 +215,6 b' class ConflictResolutionRequired(Interve' | |||
|
182 | 215 | ) |
|
183 | 216 | |
|
184 | 217 | |
|
185 | class Abort(Hint, Exception): | |
|
186 | """Raised if a command needs to print an error and exit.""" | |
|
187 | ||
|
188 | def __init__(self, message, hint=None, detailed_exit_code=None): | |
|
189 | # type: (bytes, Optional[bytes]) -> None | |
|
190 | self.message = message | |
|
191 | self.hint = hint | |
|
192 | self.detailed_exit_code = detailed_exit_code | |
|
193 | # Pass the message into the Exception constructor to help extensions | |
|
194 | # that look for exc.args[0]. | |
|
195 | Exception.__init__(self, message) | |
|
196 | ||
|
197 | def __bytes__(self): | |
|
198 | return self.message | |
|
199 | ||
|
200 | if pycompat.ispy3: | |
|
201 | ||
|
202 | def __str__(self): | |
|
203 | # the output would be unreadable if the message was translated, | |
|
204 | # but do not replace it with encoding.strfromlocal(), which | |
|
205 | # may raise another exception. | |
|
206 | return pycompat.sysstr(self.__bytes__()) | |
|
207 | ||
|
208 | def format(self): | |
|
209 | # type: () -> bytes | |
|
210 | from .i18n import _ | |
|
211 | ||
|
212 | message = _(b"abort: %s\n") % self.message | |
|
213 | if self.hint: | |
|
214 | message += _(b"(%s)\n") % self.hint | |
|
215 | return message | |
|
216 | ||
|
217 | ||
|
218 | 218 | class InputError(Abort): |
|
219 | 219 | """Indicates that the user made an error in their input. |
|
220 | 220 |
General Comments 0
You need to be logged in to leave comments.
Login now