Skip to content

Commit 2b769f0

Browse files
committed
Wire WITH on error stop load-file option to copy/*on-error-stop* in v4
The WITH on error stop / on error resume next options were already parsed by the grammar and surfaced as :on-error-stop in with-options by ast.clj, but run-command in core.clj never read them. Only the --on-error-stop CLI flag set copy/*on-error-stop*. Fix: extract :on-error-stop from with-options and add it to the binding block alongside batch-rows, batch-size, etc. Use (some? v) instead of (or v ...) since the option is boolean: a false value from a future explicit on-error-resume path must not be ignored. Add parser tests verifying that: - WITH on error stop → :on-error-stop true in with-options - WITH on error resume next → :on-error-stop absent from with-options
1 parent e15cdf9 commit 2b769f0

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎clojure/src/pgloader/core.clj‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,13 @@
454454
opts-batch-size (some-> (get (:with-options cmd) :batch-size) (Long/parseLong))
455455
opts-prefetch-rows (some-> (get (:with-options cmd) :prefetch-rows) (long))
456456
opts-batch-concurr (some-> (get (:with-options cmd) :batch-concurrency) (long))
457+
opts-on-error-stop (get (:with-options cmd) :on-error-stop)
457458
_ (when (and opts-prefetch-rows opts-batch-concurr)
458459
(throw (ex-info "pgloader: 'batch concurrency' (deprecated) and 'prefetch rows' cannot both appear in the same WITH clause; remove 'batch concurrency'" {})))]
459460
(binding [copy/*batch-rows* (or opts-batch-rows copy/*batch-rows*)
460461
copy/*batch-size* (or opts-batch-size copy/*batch-size*)
461-
copy/*prefetch-queue-capacity* (or opts-prefetch-rows opts-batch-concurr copy/*prefetch-queue-capacity*)]
462+
copy/*prefetch-queue-capacity* (or opts-prefetch-rows opts-batch-concurr copy/*prefetch-queue-capacity*)
463+
copy/*on-error-stop* (if (some? opts-on-error-stop) opts-on-error-stop copy/*on-error-stop*)]
462464
(try
463465
;; Send MySQL-specific SET params to the MySQL source connection before catalog fetch
464466
(when (#{:mysql :mariadb} (:type source-uri))

‎clojure/test/pgloader/load_file/parser_test.clj‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,3 +552,20 @@
552552
WITH downcase identifiers;")]
553553
(is (:ok result) (str "Parse failed: " (:error result)))
554554
(is (true? (get-in result [:ok :with-options :downcase-ids]))))))
555+
556+
(deftest test-with-on-error-stop
557+
(testing "WITH on error stop sets :on-error-stop true in with-options"
558+
(let [result (parser/parse-string
559+
"LOAD DATABASE FROM sqlite:///tmp/foo.db
560+
INTO postgresql:///target
561+
WITH on error stop;")]
562+
(is (:ok result) (str "Parse failed: " (:error result)))
563+
(is (true? (get-in result [:ok :with-options :on-error-stop])))))
564+
565+
(testing "WITH on error resume next does not set :on-error-stop"
566+
(let [result (parser/parse-string
567+
"LOAD DATABASE FROM sqlite:///tmp/foo.db
568+
INTO postgresql:///target
569+
WITH on error resume next;")]
570+
(is (:ok result) (str "Parse failed: " (:error result)))
571+
(is (nil? (get-in result [:ok :with-options :on-error-stop]))))))

0 commit comments

Comments
 (0)