From a1328dc28ba104e93138d612e99023ff9aca1333 Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Wed, 22 Jun 2011 00:25:26 -0400
Subject: [PATCH] Properly deal with string-form error messages (i.e. ones not
 coming from C++).

---
 pyopencl/__init__.py | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py
index 21f2317e..ebebb4c8 100644
--- a/pyopencl/__init__.py
+++ b/pyopencl/__init__.py
@@ -332,12 +332,17 @@ def _add_functionality():
 
     def error_str(self):
         val = self.args[0]
-        result = "%s failed: %s" % (val.routine(), 
-                status_code.to_string(val.code(), "<unknown error %d>")
-                .lower().replace("_", " "))
-        if val.what():
-            result += " - " + val.what()
-        return result
+        try:
+            val.routine
+        except AttributeError:
+            return str(val)
+        else:
+            result = "%s failed: %s" % (val.routine(), 
+                    status_code.to_string(val.code(), "<unknown error %d>")
+                    .lower().replace("_", " "))
+            if val.what():
+                result += " - " + val.what()
+            return result
 
     def error_code(self):
         return self.args[0].code()
-- 
GitLab