Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions pg_probackup2/init_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(self):
self.is_lz4_enabled = '-llz4' in pg_config['LIBS']

server_version_out = os_ops.exec_command(
[postgres, "-C", "server_version"],
[postgres, "--version"],
encoding='utf-8')
server_version = testgres.parse_pg_version(server_version_out)
parts = [*server_version.split('.'), '0', '0'][:3]
Expand Down Expand Up @@ -263,10 +263,32 @@ def test_env(self):
return self._test_env.copy()


class InitFailed(object):
"""
Placeholder used when Init() failed. Any attribute access re-raises the
original initialization error with a clear message instead of the cryptic
"'NoneType' object has no attribute ..." that a plain None would produce.
"""

def __init__(self, error):
self._error = error

def __getattr__(self, name):
if name == '_error':
raise AttributeError(name)
raise RuntimeError(
"pg_probackup initialization failed, so init_params.{0} cannot be "
"used. Fix the initialization error above. Original error: {1}"
.format(name, self._error)
) from self._error


try:
init_params = Init()
except Exception as e:
traceback.print_exc(file=sys.stderr)
logging.error(str(e))
logging.warning("testgres.plugins.probackup2.init_params is set to None.")
init_params = None
logging.warning(
"testgres.plugins.probackup2.init_params initialization failed; "
"accessing it will re-raise the original error.")
init_params = InitFailed(e)