- Notifications
You must be signed in to change notification settings - Fork35
Proposal to fix #154 (v2)#161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from7 commits
f9ddd04
2bb38dc
45b8dc0
f848a63
db0744e
5bb1510
31c7bce
b013801
c49ee4c
6a0e714
3cc19d2
7b70e9e
cd0b5f8
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -9,13 +9,14 @@ class TestgresException(Exception): | ||
@six.python_2_unicode_compatible | ||
class ExecUtilException(TestgresException): | ||
def __init__(self, message=None, command=None, exit_code=0, out=None, error=None): | ||
super(ExecUtilException, self).__init__(message) | ||
self.message = message | ||
self.command = command | ||
self.exit_code = exit_code | ||
self.out = out | ||
self.error = error | ||
def __str__(self): | ||
msg = [] | ||
@@ -24,13 +25,17 @@ def __str__(self): | ||
msg.append(self.message) | ||
if self.command: | ||
command_s = ' '.join(self.command) if isinstance(self.command, list) else self.command, | ||
msg.append(u'Command: {}'.format(command_s)) | ||
if self.exit_code: | ||
msg.append(u'Exit code: {}'.format(self.exit_code)) | ||
if self.error: | ||
msg.append(u'---- Error:\n{}'.format(self.error)) | ||
if self.out: | ||
msg.append(u'---- Out:\n{}'.format(self.out)) | ||
return self.convert_and_join(msg) | ||
@@ -98,3 +103,7 @@ class InitNodeException(TestgresException): | ||
class BackupException(TestgresException): | ||
pass | ||
class InvalidOperationException(TestgresException): | ||
pass | ||
dmitry-lipetsk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from ..exceptions import ExecUtilException | ||
class RaiseError: | ||
def UtilityExitedWithNonZeroCode(cmd, exit_code, msg_arg, error, out): | ||
assert type(exit_code) == int # noqa: E721 | ||
msg_arg_s = __class__._TranslateDataIntoString(msg_arg).strip() | ||
assert type(msg_arg_s) == str # noqa: E721 | ||
if msg_arg_s == "": | ||
msg_arg_s = "#no_error_message" | ||
message = "Utility exited with non-zero code. Error: `" + msg_arg_s + "`" | ||
raise ExecUtilException( | ||
message=message, | ||
command=cmd, | ||
exit_code=exit_code, | ||
out=out, | ||
error=error) | ||
def _TranslateDataIntoString(data): | ||
if type(data) == bytes: # noqa: E721 | ||
return __class__._TranslateDataIntoString__FromBinary(data) | ||
return str(data) | ||
def _TranslateDataIntoString__FromBinary(data): | ||
assert type(data) == bytes # noqa: E721 | ||
dmitry-lipetsk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
try: | ||
return data.decode('utf-8') | ||
dmitry-lipetsk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
except UnicodeDecodeError: | ||
pass | ||
return "#cannot_decode_text" | ||
def _BinaryIsASCII(data): | ||
assert type(data) == bytes # noqa: E721 | ||
for b in data: | ||
if not (b >= 0 and b <= 127): | ||
return False | ||
return True |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Helpers: | ||
def PrepareProcessInput(input, encoding): | ||
if not input: | ||
return None | ||
if type(input) == str: # noqa: E721 | ||
if encoding is None: | ||
return input.encode() | ||
dmitry-lipetsk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
assert type(encoding) == str # noqa: E721 | ||
return input.encode(encoding) | ||
# It is expected! | ||
assert type(input) == bytes # noqa: E721 | ||
return input |
Uh oh!
There was an error while loading.Please reload this page.