>From af0a83a4ff0356fe5b172b6c60692953d7e01bf0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Urba=C5=84ski?= <wulczer@wulczer.org>
Date: Sun, 2 Jan 2011 11:42:54 +0100
Subject: [PATCH 7/7] Do not prefix error messages with the string "PL/Python: ".

It is redundant, given the error context. Also, call pg_verifymbstr
outside of the try/catch block, because it can lead to errorneously
reporting a Python error when it is in fact a Postgres error.
---
 src/pl/plpython/expected/plpython_do.out      |    2 +-
 src/pl/plpython/expected/plpython_error.out   |   20 ++++++++++----------
 src/pl/plpython/expected/plpython_test.out    |    2 +-
 src/pl/plpython/expected/plpython_types.out   |    2 +-
 src/pl/plpython/expected/plpython_types_3.out |    2 +-
 src/pl/plpython/plpython.c                    |   13 ++++++-------
 6 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/src/pl/plpython/expected/plpython_do.out b/src/pl/plpython/expected/plpython_do.out
index 9de261a..a21b088 100644
--- a/src/pl/plpython/expected/plpython_do.out
+++ b/src/pl/plpython/expected/plpython_do.out
@@ -2,5 +2,5 @@ DO $$ plpy.notice("This is plpythonu.") $$ LANGUAGE plpythonu;
 NOTICE:  This is plpythonu.
 CONTEXT:  PL/Python anonymous code block
 DO $$ nonsense $$ LANGUAGE plpythonu;
-ERROR:  PL/Python: NameError: global name 'nonsense' is not defined
+ERROR:  NameError: global name 'nonsense' is not defined
 CONTEXT:  PL/Python anonymous code block
diff --git a/src/pl/plpython/expected/plpython_error.out b/src/pl/plpython/expected/plpython_error.out
index 87225f2..ea4a54c 100644
--- a/src/pl/plpython/expected/plpython_error.out
+++ b/src/pl/plpython/expected/plpython_error.out
@@ -8,9 +8,9 @@ CREATE FUNCTION sql_syntax_error() RETURNS text
 'plpy.execute("syntax error")'
         LANGUAGE plpythonu;
 SELECT sql_syntax_error();
-WARNING:  PL/Python: plpy.SPIError: unrecognized error in PLy_spi_execute_query
+WARNING:  plpy.SPIError: unrecognized error in PLy_spi_execute_query
 CONTEXT:  PL/Python function "sql_syntax_error"
-ERROR:  PL/Python: plpy.SPIError: syntax error at or near "syntax"
+ERROR:  plpy.SPIError: syntax error at or near "syntax"
 LINE 1: syntax error
         ^
 QUERY:  syntax error
@@ -22,7 +22,7 @@ CREATE FUNCTION exception_index_invalid(text) RETURNS text
 'return args[1]'
 	LANGUAGE plpythonu;
 SELECT exception_index_invalid('test');
-ERROR:  PL/Python: IndexError: list index out of range
+ERROR:  IndexError: list index out of range
 CONTEXT:  PL/Python function "exception_index_invalid"
 /* check handling of nested exceptions
  */
@@ -32,9 +32,9 @@ CREATE FUNCTION exception_index_invalid_nested() RETURNS text
 return rv[0]'
 	LANGUAGE plpythonu;
 SELECT exception_index_invalid_nested();
-WARNING:  PL/Python: plpy.SPIError: unrecognized error in PLy_spi_execute_query
+WARNING:  plpy.SPIError: unrecognized error in PLy_spi_execute_query
 CONTEXT:  PL/Python function "exception_index_invalid_nested"
-ERROR:  PL/Python: plpy.SPIError: function test5(unknown) does not exist
+ERROR:  plpy.SPIError: function test5(unknown) does not exist
 LINE 1: SELECT test5('foo')
                ^
 HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
@@ -54,9 +54,9 @@ return None
 '
 	LANGUAGE plpythonu;
 SELECT invalid_type_uncaught('rick');
-WARNING:  PL/Python: plpy.SPIError: unrecognized error in PLy_spi_prepare
+WARNING:  plpy.SPIError: unrecognized error in PLy_spi_prepare
 CONTEXT:  PL/Python function "invalid_type_uncaught"
-ERROR:  PL/Python: plpy.SPIError: type "test" does not exist
+ERROR:  plpy.SPIError: type "test" does not exist
 CONTEXT:  PL/Python function "invalid_type_uncaught"
 /* for what it's worth catch the exception generated by
  * the typo, and return None
@@ -77,7 +77,7 @@ return None
 '
 	LANGUAGE plpythonu;
 SELECT invalid_type_caught('rick');
-WARNING:  PL/Python: plpy.SPIError: unrecognized error in PLy_spi_prepare
+WARNING:  plpy.SPIError: unrecognized error in PLy_spi_prepare
 CONTEXT:  PL/Python function "invalid_type_caught"
 NOTICE:  type "test" does not exist
 CONTEXT:  PL/Python function "invalid_type_caught"
@@ -104,9 +104,9 @@ return None
 '
 	LANGUAGE plpythonu;
 SELECT invalid_type_reraised('rick');
-WARNING:  PL/Python: plpy.SPIError: unrecognized error in PLy_spi_prepare
+WARNING:  plpy.SPIError: unrecognized error in PLy_spi_prepare
 CONTEXT:  PL/Python function "invalid_type_reraised"
-ERROR:  PL/Python: plpy.Error: type "test" does not exist
+ERROR:  plpy.Error: type "test" does not exist
 CONTEXT:  PL/Python function "invalid_type_reraised"
 /* no typo no messing about
  */
diff --git a/src/pl/plpython/expected/plpython_test.out b/src/pl/plpython/expected/plpython_test.out
index 583a149..d92c987 100644
--- a/src/pl/plpython/expected/plpython_test.out
+++ b/src/pl/plpython/expected/plpython_test.out
@@ -73,5 +73,5 @@ NOTICE:  notice
 CONTEXT:  PL/Python function "elog_test"
 WARNING:  warning
 CONTEXT:  PL/Python function "elog_test"
-ERROR:  PL/Python: plpy.Error: error
+ERROR:  plpy.Error: error
 CONTEXT:  PL/Python function "elog_test"
diff --git a/src/pl/plpython/expected/plpython_types.out b/src/pl/plpython/expected/plpython_types.out
index a165936..982005b 100644
--- a/src/pl/plpython/expected/plpython_types.out
+++ b/src/pl/plpython/expected/plpython_types.out
@@ -596,7 +596,7 @@ CREATE FUNCTION test_type_conversion_array_error() RETURNS int[] AS $$
 return 5
 $$ LANGUAGE plpythonu;
 SELECT * FROM test_type_conversion_array_error();
-ERROR:  PL/Python: return value of function with array return type is not a Python sequence
+ERROR:  return value of function with array return type is not a Python sequence
 CONTEXT:  while creating return value
 PL/Python function "test_type_conversion_array_error"
 --
diff --git a/src/pl/plpython/expected/plpython_types_3.out b/src/pl/plpython/expected/plpython_types_3.out
index 38ddf02..eeb23b7 100644
--- a/src/pl/plpython/expected/plpython_types_3.out
+++ b/src/pl/plpython/expected/plpython_types_3.out
@@ -596,7 +596,7 @@ CREATE FUNCTION test_type_conversion_array_error() RETURNS int[] AS $$
 return 5
 $$ LANGUAGE plpython3u;
 SELECT * FROM test_type_conversion_array_error();
-ERROR:  PL/Python: return value of function with array return type is not a Python sequence
+ERROR:  return value of function with array return type is not a Python sequence
 CONTEXT:  while creating return value
 PL/Python function "test_type_conversion_array_error"
 --
diff --git a/src/pl/plpython/plpython.c b/src/pl/plpython/plpython.c
index c07913c..9ad89eb 100644
--- a/src/pl/plpython/plpython.c
+++ b/src/pl/plpython/plpython.c
@@ -3460,9 +3460,9 @@ PLy_fatal(PyObject *self, PyObject *args)
 static PyObject *
 PLy_output(volatile int level, PyObject *self, PyObject *args)
 {
-	PyObject   *volatile so;
-	char	   *volatile sv;
-	volatile MemoryContext oldcontext;
+	PyObject			*volatile so;
+	char				*volatile sv;
+	MemoryContext		 volatile oldcontext = CurrentMemoryContext;
 
 	if (PyTuple_Size(args) == 1)
 	{
@@ -3483,10 +3483,9 @@ PLy_output(volatile int level, PyObject *self, PyObject *args)
 		sv = dgettext(TEXTDOMAIN, "could not parse error message in plpy.elog");
 	}
 
-	oldcontext = CurrentMemoryContext;
+	pg_verifymbstr(sv, strlen(sv), false);
 	PG_TRY();
 	{
-		pg_verifymbstr(sv, strlen(sv), false);
 		elog(level, "%s", sv);
 	}
 	PG_CATCH();
@@ -3659,14 +3658,14 @@ PLy_elog(int elevel, const char *fmt,...)
 	{
 		if (fmt)
 			ereport(elevel,
-					(errmsg("PL/Python: %s", emsg.data),
+					(errmsg("%s", emsg.data),
 					 (xmsg) ? errdetail("%s", xmsg) : 0,
 					 (hint) ? errhint(hint) : 0,
 					 (query) ? internalerrquery(query) : 0,
 					 (position) ? internalerrposition(position) : 0));
 		else
 			ereport(elevel,
-					(errmsg("PL/Python: %s", xmsg),
+					(errmsg("%s", xmsg),
 					 (hint) ? errhint(hint) : 0,
 					 (query) ? internalerrquery(query) : 0,
 					 (position) ? internalerrposition(position) : 0));
-- 
1.7.2.3

