From f0688d6e6c595cdceef3ad218b86f064f4909b4c Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 15 Jun 2016 10:34:11 -0400 Subject: PL/Python: Clean up extended error reporting docs and tests Format the example and test code more to Python style standards. Improve whitespace. Improve documentation formatting. --- doc/src/sgml/plpython.sgml | 49 +++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 20 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/plpython.sgml b/doc/src/sgml/plpython.sgml index abc11a9ddf9..905e757ab6c 100644 --- a/doc/src/sgml/plpython.sgml +++ b/doc/src/sgml/plpython.sgml @@ -1341,13 +1341,15 @@ $$ LANGUAGE plpythonu; Utility Functions The plpy module also provides the functions - plpy.debug(msg, **kwargs), - plpy.log(msg, **kwargs), - plpy.info(msg, **kwargs), - plpy.notice(msg, **kwargs), - plpy.warning(msg, **kwargs), - plpy.error(msg, **kwargs), and - plpy.fatal(msg, **kwargs). + + plpy.debug(msg, **kwargs) + plpy.log(msg, **kwargs) + plpy.info(msg, **kwargs) + plpy.notice(msg, **kwargs) + plpy.warning(msg, **kwargs) + plpy.error(msg, **kwargs) + plpy.fatal(msg, **kwargs) + elogin PL/Python plpy.error and plpy.fatal actually raise a Python exception which, if uncaught, propagates out to @@ -1366,35 +1368,42 @@ $$ LANGUAGE plpythonu; - The msg argument is given as a positional argument. For backward compatibility, more than one positional argument can be given. In that case, the string representation of the tuple of positional arguments becomes the message reported to the client. + + + The following keyword-only arguments are accepted: - - detail, hint, - sqlstate, schema_name, - table_name, column_name, - datatype_name , constraint_name - . + + detail + hint + sqlstate + schema_name + table_name + column_name + datatype_name + constraint_name + The string representation of the objects passed as keyword-only arguments is used to enrich the messages reported to the client. For example: CREATE FUNCTION raise_custom_exception() RETURNS void AS $$ -plpy.error("custom exception message", detail = "some info about exception", hint = "hint for users") +plpy.error("custom exception message", + detail="some info about exception", + hint="hint for users") $$ LANGUAGE plpythonu; -postgres=# select raise_custom_exception(); -ERROR: XX000: plpy.Error: custom exception message +=# SELECT raise_custom_exception(); +ERROR: plpy.Error: custom exception message DETAIL: some info about exception HINT: hint for users CONTEXT: Traceback (most recent call last): - PL/Python function "raise_custom_exception", line 2, in <module> - plpy.error("custom exception message", detail = "some info about exception", hint = "hint for users") + PL/Python function "raise_custom_exception", line 4, in <module> + hint="hint for users") PL/Python function "raise_custom_exception" -LOCATION: PLy_elog, plpy_elog.c:132 -- cgit v1.2.3