Skip to content

Commit

Permalink
Extended GError: added error logging suppression and StandardHandler()
Browse files Browse the repository at this point in the history
  • Loading branch information
gildor2 committed Jun 27, 2020
1 parent 8891c2d commit 363c0d7
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 62 deletions.
19 changes: 19 additions & 0 deletions Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@ void appNotify(const char *fmt, ...)
NotifyHeader[0] = 0;
}

void CErrorContext::StandardHandler()
{
void (*PrintFunc)(const char*, ...);
PrintFunc = GError.SuppressLog ? appPrintf : appNotify;
// appNotify does some markup itself, add explicit marker for pure appPrintf
const char* Marker = GError.SuppressLog ? "\n*** " : "";

if (GError.History[0])
{
// printf("ERROR: %s\n", GError.History);
PrintFunc("%sERROR: %s\n", Marker, GError.History);
}
else
{
// printf("Unknown error\n");
PrintFunc("%sUnknown error\n", Marker);
}
}

void CErrorContext::LogHistory(const char *part)
{
if (!History[0])
Expand Down
8 changes: 8 additions & 0 deletions Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ void appOpenLogFile(const char *filename);
void appPrintf(const char *fmt, ...);

void appError(const char *fmt, ...);
#define appErrorNoLog(fmt, ...) { GError.SuppressLog = true; appError(fmt, __VA_ARGS__); }


// Log some information
Expand Down Expand Up @@ -511,17 +512,24 @@ struct CErrorContext
bool IsSwError;
// Used for error history formatting
bool WasError;
// Suppress logging error message to a file (in a case of user mistake)
bool SuppressLog;
// Call stack
char History[2048];

CErrorContext()
{
Reset();
}

void Reset()
{
memset(this, 0, sizeof(*this));
}

// Log error message to console and notify.log, do NOT exit
void StandardHandler();

void LogHistory(const char *part);
};

Expand Down
11 changes: 1 addition & 10 deletions Tools/PackageExtract/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,16 +337,7 @@ int main(int argc, char **argv)

#if DO_GUARD
} CATCH {
if (GError.History[0])
{
// printf("ERROR: %s\n", GError.History);
appNotify("ERROR: %s\n", GError.History);
}
else
{
// printf("Unknown error\n");
appNotify("Unknown error\n");
}
GError.StandardHandler();
exit(1);
}
#endif
Expand Down
11 changes: 1 addition & 10 deletions Tools/PackageTool/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,7 @@ int main(int argc, char **argv)

#if DO_GUARD
} CATCH {
if (GError.History[0])
{
// printf("ERROR: %s\n", GError.History);
appNotify("ERROR: %s\n", GError.History);
}
else
{
// printf("Unknown error\n");
appNotify("Unknown error\n");
}
GError.StandardHandler();
exit(1);
}
#endif
Expand Down
11 changes: 1 addition & 10 deletions Tools/PackageUnpack/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,7 @@ int main(int argc, char **argv)

#if DO_GUARD
} CATCH {
if (GError.History[0])
{
// printf("ERROR: %s\n", GError.History);
appNotify("ERROR: %s\n", GError.History);
}
else
{
// printf("Unknown error\n");
appNotify("Unknown error\n");
}
GError.StandardHandler();
exit(1);
}
#endif
Expand Down
11 changes: 1 addition & 10 deletions Tools/TypeInfo/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,7 @@ int main(int argc, char **argv)

#if DO_GUARD
} CATCH {
if (GError.History[0])
{
// appPrintf("ERROR: %s\n", GError.History);
appNotify("ERROR: %s\n", GError.History);
}
else
{
// appPrintf("Unknown error\n");
appNotify("Unknown error\n");
}
GError.StandardHandler();
exit(1);
}
#endif
Expand Down
11 changes: 1 addition & 10 deletions Tools/UmdExtract/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,7 @@ int main(int argc, char **argv)

#if DO_GUARD
} CATCH {
if (GError.History[0])
{
// printf("ERROR: %s\n", GError.History);
appNotify("ERROR: %s\n", GError.History);
}
else
{
// printf("Unknown error\n");
appNotify("Unknown error\n");
}
GError.StandardHandler();
exit(1);
}
#endif
Expand Down
15 changes: 3 additions & 12 deletions UmodelTool/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,21 +502,12 @@ static void ExceptionHandler()
{
FFileWriter::CleanupOnError();
#if DO_GUARD
if (GError.History[0])
{
// appPrintf("ERROR: %s\n", GError.History);
appNotify("ERROR: %s\n", GError.History);
}
else
{
// appPrintf("Unknown error\n");
appNotify("Unknown error\n");
}
GError.StandardHandler();
#endif // DO_GUARD
#if HAS_UI
#if HAS_UI
if (GApplication.GuiShown)
GApplication.ShowErrorDialog();
#endif // HAS_UI
#endif // HAS_UI
exit(1);
}

Expand Down

0 comments on commit 363c0d7

Please sign in to comment.