|
| 1 | +# coding: utf-8 |
| 2 | + |
| 3 | +import six |
| 4 | + |
| 5 | + |
| 6 | +class TestgresException(Exception): |
| 7 | + pass |
| 8 | + |
| 9 | + |
| 10 | +class PortForException(TestgresException): |
| 11 | + pass |
| 12 | + |
| 13 | + |
| 14 | +@six.python_2_unicode_compatible |
| 15 | +class ExecUtilException(TestgresException): |
| 16 | + def __init__(self, message=None, command=None, exit_code=0, out=None, error=None): |
| 17 | + super(ExecUtilException, self).__init__(message) |
| 18 | + |
| 19 | + self.message = message |
| 20 | + self.command = command |
| 21 | + self.exit_code = exit_code |
| 22 | + self.out = out |
| 23 | + self.error = error |
| 24 | + |
| 25 | + def __str__(self): |
| 26 | + msg = [] |
| 27 | + |
| 28 | + if self.message: |
| 29 | + msg.append(self.message) |
| 30 | + |
| 31 | + if self.command: |
| 32 | + command_s = ' '.join(self.command) if isinstance(self.command, list) else self.command |
| 33 | + msg.append(u'Command: {}'.format(command_s)) |
| 34 | + |
| 35 | + if self.exit_code: |
| 36 | + msg.append(u'Exit code: {}'.format(self.exit_code)) |
| 37 | + |
| 38 | + if self.error: |
| 39 | + msg.append(u'---- Error:\n{}'.format(self.error)) |
| 40 | + |
| 41 | + if self.out: |
| 42 | + msg.append(u'---- Out:\n{}'.format(self.out)) |
| 43 | + |
| 44 | + return self.convert_and_join(msg) |
| 45 | + |
| 46 | + @staticmethod |
| 47 | + def convert_and_join(msg_list): |
| 48 | + # Convert each byte element in the list to str |
| 49 | + str_list = [six.text_type(item, 'utf-8') if isinstance(item, bytes) else six.text_type(item) for item in |
| 50 | + msg_list] |
| 51 | + |
| 52 | + # Join the list into a single string with the specified delimiter |
| 53 | + return six.text_type('\n').join(str_list) |
| 54 | + |
| 55 | + |
| 56 | +@six.python_2_unicode_compatible |
| 57 | +class QueryException(TestgresException): |
| 58 | + def __init__(self, message=None, query=None): |
| 59 | + super(QueryException, self).__init__(message) |
| 60 | + |
| 61 | + self.message = message |
| 62 | + self.query = query |
| 63 | + |
| 64 | + def __str__(self): |
| 65 | + msg = [] |
| 66 | + |
| 67 | + if self.message: |
| 68 | + msg.append(self.message) |
| 69 | + |
| 70 | + if self.query: |
| 71 | + msg.append(u'Query: {}'.format(self.query)) |
| 72 | + |
| 73 | + return six.text_type('\n').join(msg) |
| 74 | + |
| 75 | + |
| 76 | +class TimeoutException(QueryException): |
| 77 | + pass |
| 78 | + |
| 79 | + |
| 80 | +class CatchUpException(QueryException): |
| 81 | + pass |
| 82 | + |
| 83 | + |
| 84 | +@six.python_2_unicode_compatible |
| 85 | +class StartNodeException(TestgresException): |
| 86 | + def __init__(self, message=None, files=None): |
| 87 | + super(StartNodeException, self).__init__(message) |
| 88 | + |
| 89 | + self.message = message |
| 90 | + self.files = files |
| 91 | + |
| 92 | + def __str__(self): |
| 93 | + msg = [] |
| 94 | + |
| 95 | + if self.message: |
| 96 | + msg.append(self.message) |
| 97 | + |
| 98 | + for f, lines in self.files or []: |
| 99 | + msg.append(u'{}\n----\n{}\n'.format(f, lines)) |
| 100 | + |
| 101 | + return six.text_type('\n').join(msg) |
| 102 | + |
| 103 | + |
| 104 | +class InitNodeException(TestgresException): |
| 105 | + pass |
| 106 | + |
| 107 | + |
| 108 | +class BackupException(TestgresException): |
| 109 | + pass |
| 110 | + |
| 111 | + |
| 112 | +class InvalidOperationException(TestgresException): |
| 113 | + pass |
0 commit comments