You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-15 01:04:37 +02:00
Improved error handling in build-code binary.
Show a full stack trace instead of just the error.
This commit is contained in:
122
src/build/main.c
122
src/build/main.c
@ -20,65 +20,87 @@ Code Builder
|
|||||||
int
|
int
|
||||||
main(const int argListSize, const char *const argList[])
|
main(const int argListSize, const char *const argList[])
|
||||||
{
|
{
|
||||||
// Check parameters
|
// Set stack trace and mem context error cleanup handlers
|
||||||
CHECK(ParamInvalidError, argListSize >= 2 && argListSize <= 4, "only one to three parameters allowed");
|
static const ErrorHandlerFunction errorHandlerList[] = {stackTraceClean, memContextClean};
|
||||||
|
errorHandlerSet(errorHandlerList, LENGTH_OF(errorHandlerList));
|
||||||
|
|
||||||
// Initialize logging
|
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||||
logInit(logLevelWarn, logLevelError, logLevelOff, false, 0, 1, false);
|
FUNCTION_LOG_PARAM(INT, argListSize);
|
||||||
|
FUNCTION_LOG_PARAM(CHARPY, argList);
|
||||||
|
FUNCTION_LOG_END();
|
||||||
|
|
||||||
// Get current working directory
|
int result = 0;
|
||||||
char currentWorkDir[1024];
|
|
||||||
THROW_ON_SYS_ERROR(getcwd(currentWorkDir, sizeof(currentWorkDir)) == NULL, FormatError, "unable to get cwd");
|
|
||||||
|
|
||||||
// Get repo path (cwd if it was not passed)
|
TRY_BEGIN()
|
||||||
const String *pathRepo = strPath(STR(currentWorkDir));
|
|
||||||
String *pathBuild = strCat(strNew(), pathRepo);
|
|
||||||
|
|
||||||
if (argListSize >= 3)
|
|
||||||
{
|
{
|
||||||
const String *const pathArg = STR(argList[2]);
|
// Check parameters
|
||||||
|
CHECK(ParamInvalidError, argListSize >= 2 && argListSize <= 4, "only one to three parameters allowed");
|
||||||
|
|
||||||
if (strBeginsWith(pathArg, FSLASH_STR))
|
// Initialize logging
|
||||||
pathRepo = strPath(pathArg);
|
logInit(logLevelWarn, logLevelError, logLevelOff, false, 0, 1, false);
|
||||||
else
|
|
||||||
pathRepo = strPathAbsolute(pathArg, STR(currentWorkDir));
|
|
||||||
|
|
||||||
pathBuild = strDup(pathRepo);
|
// Get current working directory
|
||||||
|
char currentWorkDir[1024];
|
||||||
|
THROW_ON_SYS_ERROR(getcwd(currentWorkDir, sizeof(currentWorkDir)) == NULL, FormatError, "unable to get cwd");
|
||||||
|
|
||||||
|
// Get repo path (cwd if it was not passed)
|
||||||
|
const String *pathRepo = strPath(STR(currentWorkDir));
|
||||||
|
String *pathBuild = strCat(strNew(), pathRepo);
|
||||||
|
|
||||||
|
if (argListSize >= 3)
|
||||||
|
{
|
||||||
|
const String *const pathArg = STR(argList[2]);
|
||||||
|
|
||||||
|
if (strBeginsWith(pathArg, FSLASH_STR))
|
||||||
|
pathRepo = strPath(pathArg);
|
||||||
|
else
|
||||||
|
pathRepo = strPathAbsolute(pathArg, STR(currentWorkDir));
|
||||||
|
|
||||||
|
pathBuild = strDup(pathRepo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the build path was specified
|
||||||
|
if (argListSize >= 4)
|
||||||
|
{
|
||||||
|
const String *const pathArg = STR(argList[3]);
|
||||||
|
|
||||||
|
if (strBeginsWith(pathArg, FSLASH_STR))
|
||||||
|
pathBuild = strDup(pathArg);
|
||||||
|
else
|
||||||
|
pathBuild = strPathAbsolute(pathArg, STR(currentWorkDir));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Repo and build storage
|
||||||
|
const Storage *const storageRepo = storagePosixNewP(pathRepo);
|
||||||
|
const Storage *const storageBuild = storagePosixNewP(pathBuild, .write = true);
|
||||||
|
|
||||||
|
// Config
|
||||||
|
if (strEqZ(STRDEF("config"), argList[1]))
|
||||||
|
bldCfgRender(storageBuild, bldCfgParse(storageRepo), true);
|
||||||
|
|
||||||
|
// Error
|
||||||
|
if (strEqZ(STRDEF("error"), argList[1]))
|
||||||
|
bldErrRender(storageBuild, bldErrParse(storageRepo));
|
||||||
|
|
||||||
|
// Help
|
||||||
|
if (strEqZ(STRDEF("help"), argList[1]))
|
||||||
|
{
|
||||||
|
const BldCfg bldCfg = bldCfgParse(storageRepo);
|
||||||
|
bldHlpRender(storageBuild, bldCfg, bldHlpParse(storageRepo, bldCfg));
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostgreSQL
|
||||||
|
if (strEqZ(STRDEF("postgres"), argList[1]))
|
||||||
|
bldPgRender(storageBuild, bldPgParse(storageRepo));
|
||||||
}
|
}
|
||||||
|
CATCH_FATAL()
|
||||||
// If the build path was specified
|
|
||||||
if (argListSize >= 4)
|
|
||||||
{
|
{
|
||||||
const String *const pathArg = STR(argList[3]);
|
LOG_FMT(
|
||||||
|
errorTypeCode(&AssertError) ? logLevelAssert : logLevelError, errorCode(), "%s\n%s", errorMessage(), errorStackTrace());
|
||||||
|
|
||||||
if (strBeginsWith(pathArg, FSLASH_STR))
|
result = errorCode();
|
||||||
pathBuild = strDup(pathArg);
|
|
||||||
else
|
|
||||||
pathBuild = strPathAbsolute(pathArg, STR(currentWorkDir));
|
|
||||||
}
|
}
|
||||||
|
TRY_END();
|
||||||
|
|
||||||
// Repo and build storage
|
FUNCTION_LOG_RETURN(INT, result);
|
||||||
const Storage *const storageRepo = storagePosixNewP(pathRepo);
|
|
||||||
const Storage *const storageBuild = storagePosixNewP(pathBuild, .write = true);
|
|
||||||
|
|
||||||
// Config
|
|
||||||
if (strEqZ(STRDEF("config"), argList[1]))
|
|
||||||
bldCfgRender(storageBuild, bldCfgParse(storageRepo), true);
|
|
||||||
|
|
||||||
// Error
|
|
||||||
if (strEqZ(STRDEF("error"), argList[1]))
|
|
||||||
bldErrRender(storageBuild, bldErrParse(storageRepo));
|
|
||||||
|
|
||||||
// Help
|
|
||||||
if (strEqZ(STRDEF("help"), argList[1]))
|
|
||||||
{
|
|
||||||
const BldCfg bldCfg = bldCfgParse(storageRepo);
|
|
||||||
bldHlpRender(storageBuild, bldCfg, bldHlpParse(storageRepo, bldCfg));
|
|
||||||
}
|
|
||||||
|
|
||||||
// PostgreSQL
|
|
||||||
if (strEqZ(STRDEF("postgres"), argList[1]))
|
|
||||||
bldPgRender(storageBuild, bldPgParse(storageRepo));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user