Skip to content

Commit

Permalink
app_python: remove function name from log messages when handling exce…
Browse files Browse the repository at this point in the history
…ptions

- it is added automatically by log defines (resulted in duplicate
  strings)
  • Loading branch information
miconda committed Apr 27, 2016
1 parent a712dc3 commit c7175f6
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions modules/app_python/python_support.c
Expand Up @@ -52,13 +52,13 @@ void python_handle_exception(const char *fmt, ...)
PyErr_Fetch(&exception, &v, &tb);
PyErr_Clear();
if (exception == NULL) {
LM_ERR("python_handle_exception(): Can't get traceback, PyErr_Fetch() has failed.\n");
LM_ERR("Can't get traceback, PyErr_Fetch() has failed.\n");
return;
}

PyErr_NormalizeException(&exception, &v, &tb);
if (exception == NULL) {
LM_ERR("python_handle_exception(): Can't get traceback, PyErr_NormalizeException() has failed.\n");
LM_ERR("Can't get traceback, PyErr_NormalizeException() has failed.\n");
return;
}

Expand All @@ -67,30 +67,31 @@ void python_handle_exception(const char *fmt, ...)
Py_XDECREF(v);
Py_XDECREF(tb);
if (args == NULL) {
LM_ERR("python_handle_exception(): Can't get traceback, PyTuple_Pack() has failed.\n");
LM_ERR("Can't get traceback, PyTuple_Pack() has failed.\n");
return;
}

pResult = PyObject_CallObject(format_exc_obj, args);
Py_DECREF(args);
if (pResult == NULL) {
LM_ERR("python_handle_exception(): Can't get traceback, traceback.format_exception() has failed.\n");
LM_ERR("Can't get traceback, traceback.format_exception() has failed.\n");
return;
}

buflen = 1;
buf = (char *)pkg_realloc(NULL, buflen * sizeof(char));
if (!buf)
{
LM_ERR("python_handle_exception(): Can't allocate memory (%lu bytes), pkg_realloc() has failed. Not enough memory.\n", (unsigned long)(buflen * sizeof(char *)));
LM_ERR("Can't allocate memory (%lu bytes), pkg_realloc() has failed."
" Not enough memory.\n", (unsigned long)(buflen * sizeof(char *)));
return;
}
memset(buf, 0, buflen * sizeof(char));

for (i = 0; i < PySequence_Size(pResult); i++) {
line = PySequence_GetItem(pResult, i);
if (line == NULL) {
LM_ERR("python_handle_exception(): Can't get traceback, PySequence_GetItem() has failed.\n");
LM_ERR("Can't get traceback, PySequence_GetItem() has failed.\n");
Py_DECREF(pResult);
if (buf)
pkg_free(buf);
Expand All @@ -100,7 +101,7 @@ void python_handle_exception(const char *fmt, ...)
msg = PyString_AsString(line);

if (msg == NULL) {
LM_ERR("python_handle_exception(): Can't get traceback, PyString_AsString() has failed.\n");
LM_ERR("Can't get traceback, PyString_AsString() has failed.\n");
Py_DECREF(line);
Py_DECREF(pResult);
if (buf)
Expand All @@ -114,7 +115,8 @@ void python_handle_exception(const char *fmt, ...)
buf = (char *)pkg_realloc(buf, buflen * sizeof(char *));
if (!buf)
{
LM_ERR("python_handle_exception(): Can't allocate memory (%lu bytes), pkg_realloc() has failed. Not enough memory.\n", (unsigned long)(buflen * sizeof(char *)));
LM_ERR("Can't allocate memory (%lu bytes), pkg_realloc() has failed."
" Not enough memory.\n", (unsigned long)(buflen * sizeof(char *)));
Py_DECREF(line);
Py_DECREF(pResult);
return;
Expand Down Expand Up @@ -146,14 +148,15 @@ PyObject *InitTracebackModule()

pModule = PyImport_ImportModule("traceback");
if (pModule == NULL) {
LM_ERR("InitTracebackModule(): Cannot import module 'traceback'.\n");
LM_ERR("Cannot import module 'traceback'.\n");
return NULL;
}

pTracebackObject = PyObject_GetAttrString(pModule, "format_exception");
Py_DECREF(pModule);
if (pTracebackObject == NULL || !PyCallable_Check(pTracebackObject)) {
LM_ERR("InitTracebackModule(): AttributeError: 'module' object 'traceback' has no attribute 'format_exception'.\n");
LM_ERR("AttributeError: 'module' object 'traceback' has no attribute"
" 'format_exception'.\n");
Py_XDECREF(pTracebackObject);
return NULL;
}
Expand All @@ -173,7 +176,8 @@ char *make_message(const char *fmt, ...)
p = (char *)pkg_realloc(NULL, size * sizeof(char *));
if (!p)
{
LM_ERR("make_message(): Can't allocate memory (%lu bytes), pkg_malloc() has failed: Not enough memory.\n", (unsigned long)(size * sizeof(char *)));
LM_ERR("Can't allocate memory (%lu bytes), pkg_malloc() has failed:"
" Not enough memory.\n", (unsigned long)(size * sizeof(char *)));
return NULL;
}
memset(p, 0, size * sizeof(char *));
Expand All @@ -195,7 +199,8 @@ char *make_message(const char *fmt, ...)
np = (char *)pkg_realloc(p, size * sizeof(char *));
if (!np)
{
LM_ERR("make_message(): Can't allocate memory (%lu bytes), pkg_realloc() has failed: Not enough memory.\n", (unsigned long)size * sizeof(char *));
LM_ERR("Can't allocate memory (%lu bytes), pkg_realloc() has failed:"
" Not enough memory.\n", (unsigned long)size * sizeof(char *));
if (p)
pkg_free(p);
return NULL;
Expand Down

0 comments on commit c7175f6

Please sign in to comment.