1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-12 10:04:14 +02:00

Move error modules to common/error directory.

There are already enough files to warrant a separate directory and more are coming.

Also remove extraneous includes.
This commit is contained in:
David Steele 2023-04-06 10:38:49 +04:00
parent ff98636e41
commit 801e396dac
33 changed files with 42 additions and 57 deletions

View File

@ -65,7 +65,7 @@ Memory is allocated inside contexts and can be long lasting (for objects) or tem
Logging is used for debugging with the built-in macros `FUNCTION_LOG_*()` and `FUNCTION_TEST_*()` which are used to trace parameters passed to/returned from functions. `FUNCTION_LOG_*()` macros are used for production logging whereas `FUNCTION_TEST_*()` macros will be compiled out of production code. For functions where no parameter is valuable enough to justify the cost of debugging in production, use `FUNCTION_TEST_BEGIN()/FUNCTION_TEST_END()`, else use `FUNCTION_LOG_BEGIN(someLogLevel)/FUNCTION_LOG_END()`. See [debug.h](https://github.com/pgbackrest/pgbackrest/blob/main/src/common/debug.h) for more details and the [Coding Example](#coding-example) below.
Logging is also used for providing information to the user via the `LOG_*()` macros, such as `LOG_INFO("some informational message")` and `LOG_WARN_FMT("no prior backup exists, %s backup has been changed to full", strZ(cfgOptionDisplay(cfgOptType)))` and also via `THROW_*()` macros for throwing an error. See [log.h](https://github.com/pgbackrest/pgbackrest/blob/main/src/common/log.h) and [error.h](https://github.com/pgbackrest/pgbackrest/blob/main/src/common/error.h) for more details and the [Coding Example](#coding-example) below.
Logging is also used for providing information to the user via the `LOG_*()` macros, such as `LOG_INFO("some informational message")` and `LOG_WARN_FMT("no prior backup exists, %s backup has been changed to full", strZ(cfgOptionDisplay(cfgOptType)))` and also via `THROW_*()` macros for throwing an error. See [log.h](https://github.com/pgbackrest/pgbackrest/blob/main/src/common/log.h) and [error.h](https://github.com/pgbackrest/pgbackrest/blob/main/src/common/error/error.h) for more details and the [Coding Example](#coding-example) below.
### Coding Example

View File

@ -165,7 +165,7 @@
<p>Logging is used for debugging with the built-in macros <code>FUNCTION_LOG_*()</code> and <code>FUNCTION_TEST_*()</code> which are used to trace parameters passed to/returned from functions. <code>FUNCTION_LOG_*()</code> macros are used for production logging whereas <code>FUNCTION_TEST_*()</code> macros will be compiled out of production code. For functions where no parameter is valuable enough to justify the cost of debugging in production, use <code>FUNCTION_TEST_BEGIN()/FUNCTION_TEST_END()</code>, else use <code>FUNCTION_LOG_BEGIN(someLogLevel)/FUNCTION_LOG_END()</code>. See <link url="{[github-url-src-common]}/debug.h">debug.h</link> for more details and the <link section="/coding/coding-example">Coding Example</link> below.</p>
<p>Logging is also used for providing information to the user via the <code>LOG_*()</code> macros, such as <code>LOG_INFO("some informational message")</code> and <code>LOG_WARN_FMT("no prior backup exists, %s backup has been changed to full", strZ(cfgOptionDisplay(cfgOptType)))</code> and also via <code>THROW_*()</code> macros for throwing an error. See <link url="{[github-url-src-common]}/log.h">log.h</link> and <link url="{[github-url-src-common]}/error.h">error.h</link> for more details and the <link section="/coding/coding-example">Coding Example</link> below.</p>
<p>Logging is also used for providing information to the user via the <code>LOG_*()</code> macros, such as <code>LOG_INFO("some informational message")</code> and <code>LOG_WARN_FMT("no prior backup exists, %s backup has been changed to full", strZ(cfgOptionDisplay(cfgOptType)))</code> and also via <code>THROW_*()</code> macros for throwing an error. See <link url="{[github-url-src-common]}/log.h">log.h</link> and <link url="{[github-url-src-common]}/error/error.h">error.h</link> for more details and the <link section="/coding/coding-example">Coding Example</link> below.</p>
</section>
<!-- =================================================================================================================== -->

View File

@ -10,7 +10,7 @@ SRCS_COMMON = \
common/compress/bz2/compress.c \
common/debug.c \
common/encode.c \
common/error.c \
common/error/error.c \
common/io/filter/buffer.c \
common/io/filter/filter.c \
common/io/filter/group.c \

View File

@ -1,6 +1,6 @@
# Error Definitions
#
# Definitions for all C errors, auto-generated to src/common/error.auto.c.inc/.h.
# Definitions for all C errors, auto-generated to src/common/error/error.auto.c.inc/.h.
# Errors in the code that it should not be possible for the user to encounter -- i.e., a likely bug
assert:

View File

@ -52,8 +52,8 @@ bldErrRenderErrorAutoH(const Storage *const storageRepo, const BldErr bldErr)
String *error = strCatFmt(
strNew(),
"%s"
"#ifndef COMMON_ERROR_AUTO_H\n"
"#define COMMON_ERROR_AUTO_H\n",
"#ifndef COMMON_ERROR_ERROR_AUTO_H\n"
"#define COMMON_ERROR_ERROR_AUTO_H\n",
strZ(bldHeader(ERROR_MODULE, ERROR_AUTO_COMMENT)));
// Error declarations
@ -78,7 +78,7 @@ bldErrRenderErrorAutoH(const Storage *const storageRepo, const BldErr bldErr)
"\n"
"#endif\n");
bldPut(storageRepo, "src/common/error.auto.h", BUFSTR(error));
bldPut(storageRepo, "src/common/error/error.auto.h", BUFSTR(error));
}
/***********************************************************************************************************************************
@ -130,7 +130,7 @@ bldErrRenderErrorAutoC(const Storage *const storageRepo, const BldErr bldErr)
" NULL,\n"
"};\n");
bldPut(storageRepo, "src/common/error.auto.c.inc", BUFSTR(error));
bldPut(storageRepo, "src/common/error/error.auto.c.inc", BUFSTR(error));
}
/**********************************************************************************************************************************/

View File

@ -9,7 +9,6 @@ Exit Routines
#include "command/command.h"
#include "command/exit.h"
#include "common/debug.h"
#include "common/error.h"
#include "common/lock.h"
#include "common/log.h"
#include "config/config.h"

View File

@ -4,7 +4,7 @@ Assert Routines
#ifndef COMMON_ASSERT_H
#define COMMON_ASSERT_H
#include "common/error.h"
#include "common/error/error.h"
/***********************************************************************************************************************************
Asserts are used in test code to ensure that certain conditions are true. They are omitted from production builds.

View File

@ -11,7 +11,6 @@ Crypto Common
#include "common/crypto/common.h"
#include "common/debug.h"
#include "common/error.h"
#include "common/log.h"
/***********************************************************************************************************************************

View File

@ -8,7 +8,6 @@ Binary to String Encode/Decode
#include "common/debug.h"
#include "common/encode.h"
#include "common/error.h"
/***********************************************************************************************************************************
Assert that encoding type is valid. This needs to be kept up to date with the last item in the enum.

View File

@ -3,8 +3,8 @@ Error Type Definition
Automatically generated by 'build-code error' -- do not modify directly.
***********************************************************************************************************************************/
#ifndef COMMON_ERROR_AUTO_H
#define COMMON_ERROR_AUTO_H
#ifndef COMMON_ERROR_ERROR_AUTO_H
#define COMMON_ERROR_ERROR_AUTO_H
/***********************************************************************************************************************************
Error type declarations

View File

@ -9,7 +9,7 @@ Error Handler
#include <stdlib.h>
#include <string.h>
#include "common/error.h"
#include "common/error/error.h"
#include "common/macro.h"
#include "common/stackTrace.h"
@ -34,7 +34,7 @@ ERROR_DEFINE(1, TestError, false, RuntimeError);
#endif
// Include error type definitions
#include "common/error.auto.c.inc"
#include "common/error/error.auto.c.inc"
/***********************************************************************************************************************************
Maximum allowed number of nested try blocks

View File

@ -34,8 +34,8 @@ gcc's -Wclobbered warnings are almost entirely useless for catching such issues.
IMPORTANT: Never call return from within any of the error-handling blocks.
***********************************************************************************************************************************/
#ifndef COMMON_ERROR_H
#define COMMON_ERROR_H
#ifndef COMMON_ERROR_ERROR_H
#define COMMON_ERROR_ERROR_H
#include <errno.h>
#include <setjmp.h>
@ -51,7 +51,7 @@ typedef struct ErrorType ErrorType;
VR_EXTERN_DECLARE const ErrorType name
// Include error type declarations
#include "common/error.auto.h"
#include "common/error/error.auto.h"
// Declare test error
#ifdef DEBUG

View File

@ -8,7 +8,6 @@ Fork Handler
#include <unistd.h>
#include "common/debug.h"
#include "common/error.h"
#include "common/log.h"
/**********************************************************************************************************************************/

View File

@ -13,7 +13,6 @@ Log Handler
#include <unistd.h>
#include "common/debug.h"
#include "common/error.h"
#include "common/log.h"
#include "common/time.h"

View File

@ -7,7 +7,6 @@ Memory Context Manager
#include <string.h>
#include "common/debug.h"
#include "common/error.h"
#include "common/macro.h"
#include "common/memContext.h"

View File

@ -12,6 +12,7 @@ See the sections on memory context management and memory allocations below for m
#ifndef COMMON_MEMCONTEXT_H
#define COMMON_MEMCONTEXT_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@ -20,7 +21,6 @@ Memory context object
***********************************************************************************************************************************/
typedef struct MemContext MemContext;
#include "common/error.h"
#include "common/type/param.h"
/***********************************************************************************************************************************

View File

@ -13,7 +13,6 @@ Stack Trace Handler
#endif
#include "common/assert.h"
#include "common/error.h"
#include "common/macro.h"
#include "common/stackTrace.h"
@ -324,7 +323,7 @@ stackTraceBackCallback(
{
fileName = stackTraceTrimSrc(fileName);
if (strcmp(fileName, "common/error.c") == 0)
if (strcmp(fileName, "common/error/error.c") == 0)
return false;
data->result += stackTraceFmt(

View File

@ -7,7 +7,6 @@ Command and Option Configuration
#include <string.h>
#include "common/debug.h"
#include "common/error.h"
#include "common/memContext.h"
#include "config/config.intern.h"
#include "config/parse.h"

View File

@ -10,7 +10,6 @@ Command and Option Parse
#include <unistd.h>
#include "common/debug.h"
#include "common/error.h"
#include "common/ini.h"
#include "common/io/bufferRead.h"
#include "common/log.h"

View File

@ -35,7 +35,6 @@ Main
#include "command/stanza/upgrade.h"
#include "command/verify/verify.h"
#include "common/debug.h"
#include "common/error.h"
#include "common/io/fdRead.h"
#include "common/io/fdWrite.h"
#include "common/stat.h"

View File

@ -27,7 +27,7 @@ configure_file(output: 'build.auto.h', configuration: configuration)
src_common = files(
'common/debug.c',
'common/encode.c',
'common/error.c',
'common/error/error.c',
'common/io/filter/buffer.c',
'common/io/filter/filter.c',
'common/io/filter/group.c',

View File

@ -863,19 +863,19 @@ src/common/encode.h:
class: core
type: c/h
src/common/error.auto.c.inc:
src/common/error/error.auto.c.inc:
class: core/auto
type: c
src/common/error.auto.h:
src/common/error/error.auto.h:
class: core/auto
type: c/h
src/common/error.c:
src/common/error/error.c:
class: core
type: c
src/common/error.h:
src/common/error/error.h:
class: core
type: c/h

View File

@ -52,11 +52,11 @@ unit:
harness:
name: error
shim:
common/error: ~
common/error/error: ~
coverage:
- common/error
- common/error.auto: noCode
- common/error/error
- common/error/error.auto: noCode
depend:
- common/stackTrace

View File

@ -9,7 +9,6 @@ Harness for Creating Test Backups
#include "common/compress/helper.h"
#include "common/crypto/common.h"
#include "common/crypto/hash.h"
#include "common/error.h"
#include "common/lock.h"
#include "config/config.h"
#include "info/infoArchive.h"

View File

@ -4,7 +4,7 @@ Harness for Loading Test Configurations
#ifndef TEST_COMMON_HARNESS_ERROR_H
#define TEST_COMMON_HARNESS_ERROR_H
#include "common/error.h"
#include "common/error/error.h"
#include "common/type/param.h"
/***********************************************************************************************************************************

View File

@ -13,7 +13,6 @@ Server Test Harness
#include <openssl/ssl.h>
#include "common/crypto/common.h"
#include "common/error.h"
#include "common/io/socket/server.h"
#include "common/io/tls/server.h"
#include "common/io/tls/session.h"

View File

@ -8,7 +8,6 @@ C Test Harness
#include "common/assert.h"
#include "common/debug.h"
#include "common/error.h"
#include "common/harnessTest.intern.h"

View File

@ -10,7 +10,6 @@ Main
#include "command/help/help.h"
#include "command/test/test.h"
#include "common/debug.h"
#include "common/error.h"
#include "common/log.h"
#include "common/macro.h"
#include "common/memContext.h"

View File

@ -57,14 +57,14 @@ testRun(void)
TEST_STORAGE_GET(
storageTest,
"src/common/error.auto.h",
"src/common/error/error.auto.h",
COMMENT_BLOCK_BEGIN "\n"
"Error Type Definition\n"
"\n"
"Automatically generated by 'build-code error' -- do not modify directly.\n"
COMMENT_BLOCK_END "\n"
"#ifndef COMMON_ERROR_AUTO_H\n"
"#define COMMON_ERROR_AUTO_H\n"
"#ifndef COMMON_ERROR_ERROR_AUTO_H\n"
"#define COMMON_ERROR_ERROR_AUTO_H\n"
"\n"
COMMENT_BLOCK_BEGIN "\n"
"Error type declarations\n"
@ -80,7 +80,7 @@ testRun(void)
TEST_STORAGE_GET(
storageTest,
"src/common/error.auto.c.inc",
"src/common/error/error.auto.c.inc",
COMMENT_BLOCK_BEGIN "\n"
"Error Type Definition\n"
"\n"

View File

@ -1,7 +1,6 @@
/***********************************************************************************************************************************
Test Exit Routines
***********************************************************************************************************************************/
#include "common/error.h"
#include "common/log.h"
#include "config/config.h"
#include "version.h"

View File

@ -122,7 +122,7 @@ testRun(void)
String *const harnessErrorC = strCat(
strNew(), strNewBuf(storageGetP(storageNewReadP(storageRepo, STRDEF("test/src/common/harnessError.c")))));
strReplace(harnessErrorC, STRDEF("{[SHIM_MODULE]}"), STRDEF("#include \"" TEST_PATH "/repo/src/common/error.c\""));
strReplace(harnessErrorC, STRDEF("{[SHIM_MODULE]}"), STRDEF("#include \"" TEST_PATH "/repo/src/common/error/error.c\""));
// Unit test harness
// -------------------------------------------------------------------------------------------------------------------------
@ -159,11 +159,11 @@ testRun(void)
" harness:\n"
" name: error\n"
" shim:\n"
" common/error: ~\n"
" common/error/error: ~\n"
" coverage:\n"
" - common/error\n"
" - common/error.auto: noCode\n"
" - common/error.inc: included\n"
" - common/error/error\n"
" - common/error/error.auto: noCode\n"
" - common/error/error.inc: included\n"
" depend:\n"
" - common/stackTrace\n"
" - common/type/stringStatic\n"
@ -203,7 +203,7 @@ testRun(void)
" - test/common/shim\n"
" - test/common/shim2\n"
" include:\n"
" - common/error\n"
" - common/error/error\n"
" - test/common/include\n"
"\n"
"integration:\n"
@ -232,10 +232,10 @@ testRun(void)
"src/common/assert.h",
"src/common/debug.c",
"src/common/debug.h",
"src/common/error.auto.c.inc",
"src/common/error.auto.h",
"src/common/error.c",
"src/common/error.h",
"src/common/error/error.auto.c.inc",
"src/common/error/error.auto.h",
"src/common/error/error.c",
"src/common/error/error.h",
"src/common/logLevel.h",
"src/common/macro.h",
"src/common/stackTrace.c",

View File

@ -33,7 +33,7 @@ The test code is included directly so it can freely interact with the included C
#include <unistd.h>
#ifdef HRN_FEATURE_ERROR
#include "common/error.h"
#include "common/error/error.h"
#include "common/macro.h"
#endif