Improve COPY CONTEXT message parsing, fix #67.

When adding the CONTEXT message parsing I totally forgot that PostgreSQL
provides a nice error message translation capability. The code now copes
better with the situation, using a more advanced regular expression.

We could inline the known translations in the matching, but that would
be tedious to maintain, so we just use loose matching rules here.
This commit is contained in:
Dimitri Fontaine 2014-05-28 17:23:08 +02:00
parent e93ba8b887
commit ae63c9b85c

View File

@ -130,11 +130,17 @@
;;; CONTEXT: COPY errors, line 1, column b: "2006-13-11"
;;; CONTEXT: COPY byte, line 1: "hello\0world"
;;;
;;; Those error messages are a translation target, tho, so we can only
;;; assume to recognize the command tag (COPY), the comma, and a numer after
;;; a world that might be Zeile (de), línea (es), ligne (fr), riga (it),
;;; linia (pl), linha (pt), строка (ru), 行 (zh), or something else
;;; entirely.
;;;
(defun parse-copy-error-context (context)
"Given a COPY command CONTEXT error message, return the batch position
where the error comes from."
(cl-ppcre:register-groups-bind ((#'parse-integer n))
("line (\\d+)" context :sharedp t)
("COPY [^,]+, [^ ]+ (\\d+)" context :sharedp t)
(1- n)))
;;;
@ -192,7 +198,8 @@
;; the batch didn't make it, prepare error handling for next turn
((or
CL-POSTGRES-ERROR:INTEGRITY-VIOLATION
CL-POSTGRES-ERROR:DATA-EXCEPTION) (next-error-in-batch)
CL-POSTGRES-ERROR:DATA-EXCEPTION)
(next-error-in-batch)
(setf condition next-error-in-batch