From 8eea90bb51c4b4d20723cfbd354a6c513b60c199 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Thu, 14 Feb 2019 23:10:12 +0100 Subject: [PATCH] Improve Foreign Key error handling. We don't know how to parse the PostgreSQL condition sent when there is a fkey error... and the message would not contain the row number where that error happened anyway. At the moment it means that the retry-batch facility errors out for failing to realize that NIL isn't a number on which we can do arithmetic, which in itself in a little sad. In this patch we install a condition handler that knows how to deal with retry-batch failing, so that pgloader may try and continue rather than appear locked to the user, when I suspect that the debugger is waiting for input. See #836, where that's the first half of the fix. The real fix is to handle foreign key errors correctly of course. --- src/pg-copy/copy-rows-in-batch.lisp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pg-copy/copy-rows-in-batch.lisp b/src/pg-copy/copy-rows-in-batch.lisp index deb27d2..70c2481 100644 --- a/src/pg-copy/copy-rows-in-batch.lisp +++ b/src/pg-copy/copy-rows-in-batch.lisp @@ -67,9 +67,13 @@ (log-message :error "PostgreSQL [~s] ~a" table-name condition) ;; clean the current transaction before retrying new ones (let ((errors - (retry-batch table columns batch condition))) + (handler-case + (retry-batch table columns batch condition) + (condition (e) + (log-message :error "BUG: failed to retry-batch: ~a" e) + (batch-count batch))))) (log-message :debug "retry-batch found ~d errors" errors) - (update-stats :data table :rows (- errors)))) + (update-stats :data table :errs errors :rows (- errors)))) (postgresql-unavailable (condition)