Default error handler. */
| 1013 | |
| 1014 | /** Default error handler. */ |
| 1015 | void CPL_STDCALL CPLDefaultErrorHandler(CPLErr eErrClass, CPLErrorNum nError, |
| 1016 | const char *pszErrorMsg) |
| 1017 | |
| 1018 | { |
| 1019 | static int nCount = 0; |
| 1020 | static int nMaxErrors = -1; |
| 1021 | static char chErrorSeparator = ':'; |
| 1022 | |
| 1023 | if (eErrClass != CE_Debug) |
| 1024 | { |
| 1025 | if (nMaxErrors == -1) |
| 1026 | { |
| 1027 | nMaxErrors = |
| 1028 | atoi(CPLGetConfigOption("CPL_MAX_ERROR_REPORTS", "1000")); |
| 1029 | // If running GDAL as a CustomBuild Command os MSBuild, "ERROR bla:" |
| 1030 | // is considered as failing the job. This is rarely the intended |
| 1031 | // behavior |
| 1032 | const char *pszErrorSeparator = |
| 1033 | CPLGetConfigOption("CPL_ERROR_SEPARATOR", ":"); |
| 1034 | if (pszErrorSeparator[0]) |
| 1035 | chErrorSeparator = pszErrorSeparator[0]; |
| 1036 | } |
| 1037 | |
| 1038 | nCount++; |
| 1039 | if (nCount > nMaxErrors && nMaxErrors > 0) |
| 1040 | return; |
| 1041 | } |
| 1042 | |
| 1043 | if (!bLogInit) |
| 1044 | { |
| 1045 | bLogInit = true; |
| 1046 | |
| 1047 | fpLog = stderr; |
| 1048 | const char *pszLog = CPLGetConfigOption("CPL_LOG", nullptr); |
| 1049 | if (pszLog != nullptr) |
| 1050 | { |
| 1051 | const bool bAppend = |
| 1052 | CPLGetConfigOption("CPL_LOG_APPEND", nullptr) != nullptr; |
| 1053 | const char *pszAccess = bAppend ? "at" : "wt"; |
| 1054 | fpLog = CPLfopenUTF8(pszLog, pszAccess); |
| 1055 | if (fpLog == nullptr) |
| 1056 | fpLog = stderr; |
| 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | if (eErrClass == CE_Debug) |
| 1061 | { |
| 1062 | #ifndef _WIN32 |
| 1063 | CPLErrorContext *psCtx = CPLGetErrorContext(); |
| 1064 | if (psCtx != nullptr && !IS_PREFEFINED_ERROR_CTX(psCtx) && |
| 1065 | fpLog == stderr && CPLIsInteractive(stderr)) |
| 1066 | { |
| 1067 | if (psCtx->bProgressMode) |
| 1068 | { |
| 1069 | // Erase the content of the current line |
| 1070 | fprintf(stderr, "\r"); |
| 1071 | fprintf(stderr, "%s", pszErrorMsg); |
| 1072 | fflush(stderr); |
nothing calls this directly
no test coverage detected