[icinga-checkins] icinga.org: icinga2/master: Fix PythonLanguage::ExceptionInfoToString().

git at icinga.org git at icinga.org
Sat Feb 16 12:48:02 CET 2013


Module: icinga2
Branch: master
Commit: c1a98d66be08f33bcae297cde7a32bb633efb182
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=c1a98d66be08f33bcae297cde7a32bb633efb182

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Sat Feb 16 12:47:52 2013 +0100

Fix PythonLanguage::ExceptionInfoToString().

---

 lib/python/pythoninterpreter.cpp |    2 +-
 lib/python/pythonlanguage.cpp    |   18 +++++++++++++++---
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/lib/python/pythoninterpreter.cpp b/lib/python/pythoninterpreter.cpp
index ba1cc5d..8cd1b39 100644
--- a/lib/python/pythoninterpreter.cpp
+++ b/lib/python/pythoninterpreter.cpp
@@ -105,7 +105,7 @@ void PythonInterpreter::ProcessCall(const ScriptTask::Ptr& task, const String& f
 			Py_XDECREF(pvalue);
 			Py_XDECREF(ptraceback);
 
-			BOOST_THROW_EXCEPTION(runtime_error("Error in Python script:" + msg));
+			BOOST_THROW_EXCEPTION(runtime_error("Error in Python script: " + msg));
 		}
 
 		Value vresult = PythonLanguage::MarshalFromPython(result);
diff --git a/lib/python/pythonlanguage.cpp b/lib/python/pythonlanguage.cpp
index d6d8337..62ab582 100644
--- a/lib/python/pythonlanguage.cpp
+++ b/lib/python/pythonlanguage.cpp
@@ -225,13 +225,25 @@ String PythonLanguage::ExceptionInfoToString(PyObject *type, PyObject *exc, PyOb
 	Py_DECREF(format_exception);
 	Py_DECREF(tb_dict);
 
-	if (!result || !PyString_Check(result)) {
+	if (!result || !PyList_Check(result)) {
 		Py_XDECREF(result);
 
-		return "format_exception() returned something that is not a string.";
+		return "format_exception() returned something that is not a list.";
 	}
 
-	String msg = PyString_AsString(result);
+	String msg;
+
+	for (Py_ssize_t i = 0; i < PyList_Size(result); i++) {
+		PyObject *li = PyList_GetItem(result, i);
+
+		if (!li || !PyString_Check(li)) {
+			Py_DECREF(result);
+
+			return "format_exception() returned something that is not a list of strings.";
+		}
+
+		msg += PyString_AsString(li);
+	}
 
 	Py_DECREF(result);
 





More information about the icinga-checkins mailing list