Revision 3595
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql_gen.py | ||
---|---|---|
665 | 665 |
plpythonu_error_handler = ExcHandler('internal_error', '''\ |
666 | 666 |
-- Handle PL/Python exceptions |
667 | 667 |
DECLARE |
668 |
matches text[] := regexp_matches(SQLERRM, E'^PL/Python: (\\\\w+): (.*)$');
|
|
669 |
-- .* matches everything, including \\n
|
|
668 |
matches text[] := regexp_matches(SQLERRM, |
|
669 |
E'^(?:PL/Python: )?(\\\\w+): (.*)$'); -- .* also matches \\n
|
|
670 | 670 |
exc_name text := matches[1]; |
671 | 671 |
msg text := matches[2]; |
672 | 672 |
BEGIN |
673 |
-- Re-raise non-PL/Python exceptions |
|
674 |
IF exc_name IS NULL THEN '''+reraise_exc+'''\ |
|
675 | 673 |
-- Translate specific Python exception types to PostgreSQL error codes |
676 |
ELSIF exc_name = 'ValueError' THEN RAISE data_exception USING MESSAGE = msg; |
|
674 |
IF exc_name = 'ValueError' THEN |
|
675 |
RAISE data_exception USING MESSAGE = msg; |
|
677 | 676 |
/* Re-raise other PL/Python exceptions with the PL/Python prefix removed. |
678 | 677 |
This allows the exception to be parsed like a native exception. */ |
679 |
ELSE RAISE E'%\\nDETAIL: Python exception class: %', msg, exc_name; |
|
678 |
ELSIF exc_name IS NOT NULL AND SQLERRM LIKE '%PL/Python%' THEN |
|
679 |
RAISE E'%\\nDETAIL: Python exception class: %', msg, exc_name; |
|
680 |
-- Re-raise non-PL/Python exceptions |
|
681 |
ELSE |
|
682 |
'''+reraise_exc+'''\ |
|
680 | 683 |
END IF; |
681 | 684 |
END; |
682 | 685 |
''') |
Also available in: Unified diff
sql_gen.py: plpythonu_error_handler: Fixed bug where not all PL/Python exceptions start with "PL/Python: " (e.g. on PostgreSQL 9.1 on vegbiendev), so the PL/Python prefix must be optional. Refactored to put IF clause for non-PL/Python exception at end for a more logical ordering of the conditions.