You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2026-10-23 21:28:56 +03:00
Most of these are prose in a python docstring or comment wrapped a few characters wide, which black does not reflow, and macro continuation backslashes left stranded past the margin. The rest are long calls broken after the first parenthesis, section separator comments with too many dashes, and long expectation strings split along what they hold. A few long shell commands in the workflows are wrapped with continuations. hrnTestResultDiff() had a continuation backslash left over from when it was a macro, which spliced the closing brace onto the line above it. It is removed. The linter that enforces the limit follows, so this commit is only the reformatting and can be ignored by blame.
63 lines
2.5 KiB
Python
63 lines
2.5 KiB
Python
"""Render Error Data.
|
|
|
|
Writes the error type declarations and definitions. The definitions include the list the C indexes by code, which is why an error
|
|
can be removed from the declaration but its code should not be reused."""
|
|
|
|
####################################################################################################################################
|
|
import os
|
|
|
|
from common.render import bld_comment_block, bld_enum, bld_header
|
|
from common.storage import file_write_differs
|
|
|
|
_MODULE = "error"
|
|
_DESCRIPTION = "Error Type Definition"
|
|
|
|
|
|
####################################################################################################################################
|
|
def _err_name(name):
|
|
"""Build the C name of an error, e.g. "file-open" becomes "FileOpenError"."""
|
|
|
|
return bld_enum("", name) + "Error"
|
|
|
|
|
|
####################################################################################################################################
|
|
def _render_error_auto_h(err_list):
|
|
"""Render error.auto.h, which declares every error type."""
|
|
|
|
result = bld_header(_MODULE, _DESCRIPTION) + "#ifndef COMMON_ERROR_ERROR_AUTO_H\n#define COMMON_ERROR_ERROR_AUTO_H\n"
|
|
|
|
result += "\n" + bld_comment_block("Error type declarations")
|
|
|
|
for err in err_list:
|
|
result += "ERROR_DECLARE(%s);\n" % _err_name(err.name)
|
|
|
|
return result + "\n#endif\n"
|
|
|
|
|
|
####################################################################################################################################
|
|
def _render_error_auto_c(err_list):
|
|
"""Render error.auto.c.inc, which defines every error type and the array the C looks them up in."""
|
|
|
|
result = bld_header(_MODULE, _DESCRIPTION)
|
|
|
|
result += "\n" + bld_comment_block("Error type definitions")
|
|
|
|
for err in err_list:
|
|
result += "ERROR_DEFINE(%3u, %s, %s, RuntimeError);\n" % (err.code, _err_name(err.name), "true" if err.fatal else "false")
|
|
|
|
result += "\n" + bld_comment_block("Error type array")
|
|
result += "static const ErrorType *const errorTypeList[] =\n{\n"
|
|
|
|
for err in err_list:
|
|
result += " &%s,\n" % _err_name(err.name)
|
|
|
|
return result + " NULL,\n};\n"
|
|
|
|
|
|
####################################################################################################################################
|
|
def bld_err_render(path_build, err_list):
|
|
"""Render the error files."""
|
|
|
|
file_write_differs(os.path.join(path_build, "src/common/error/error.auto.h"), _render_error_auto_h(err_list))
|
|
file_write_differs(os.path.join(path_build, "src/common/error/error.auto.c.inc"), _render_error_auto_c(err_list))
|