Skip to content

Commit eeefcaa

Browse files
dimitriDimCitus
andauthored
SBCL compiler notes should not be fatal to pgloader. (#1411)
* SBCL compiler notes should not be fatal to pgloader. The compile function returns warnings-p and failure-p values, use that to decide if the code could be compiled, and only signal a condition when it has been fatal to compiling the code at run-time. The SBCL compiler is getting smarter at removing unreachable code, and it looks like pgloader is producing some unreachable code from parsing the user provided commands. * Let's make the code look like actual lisp code now. * Another fix. * Improve condition handling and simplify processing of compile values. We don't need to react to any condition signaled from inside pgloader, only to errors and serious-conditions (an error is a serious-condition). With that, we can just ignore the compiler warnings and style notes. * Fix the handler-bind to only consider serious-conditions too. * Capture compiler output as log it as a debug level message. * Fix previous attempt. * Improve capturing of the compiler output (include summary). * Actually call the new compile function in all places. Co-authored-by: Dimitri Fontaine <[email protected]>
1 parent 2c52da1 commit eeefcaa

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

src/api.lisp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ Parameters here are meant to be already parsed, see parse-cli-optargs."
157157
(typecase source
158158
(function (list source))
159159

160-
(list (list (compile nil source)))
160+
(list (list (compile-lisp-command source)))
161161

162-
(pathname (mapcar (lambda (expr) (compile nil expr))
162+
(pathname (mapcar #'compile-lisp-command
163163
(parse-commands-from-file source)))
164164

165-
(t (mapcar (lambda (expr) (compile nil expr))
165+
(t (mapcar #'compile-lisp-command
166166
(if (probe-file source)
167167
(parse-commands-from-file source)
168168
(parse-commands source)))))))
@@ -172,6 +172,30 @@ Parameters here are meant to be already parsed, see parse-cli-optargs."
172172
:do (when flush-summary
173173
(flush-summary :reset t))))))
174174

175+
(defun compile-lisp-command (source)
176+
"SOURCE must be lisp source code, a list form."
177+
(let (function warnings-p failure-p notes)
178+
;; capture the compiler notes and warnings
179+
(setf notes
180+
(with-output-to-string (stream)
181+
(let ((*standard-output* stream)
182+
(*error-output* stream)
183+
(*trace-output* stream))
184+
(with-compilation-unit (:override t)
185+
(setf (values function warnings-p failure-p)
186+
(compile nil source))))))
187+
188+
;; log the captured compiler output at the DEBUG level
189+
(when (and notes (string/= notes ""))
190+
(let ((pp-source (with-output-to-string (s) (pprint source s))))
191+
(log-message :debug "While compiling:~%~a~%~a" pp-source notes)))
192+
193+
;; and signal an error if we failed to compile our lisp code
194+
(cond
195+
(failure-p (error "Failed to compile code: ~a~%~a" source notes))
196+
(warnings-p function)
197+
(t function))))
198+
175199

176200
;;;
177201
;;; Main API to use from outside of pgloader.

src/main.lisp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,16 @@
315315
;; meaningful backtrace to the user in case of unexpected
316316
;; conditions being signaled.
317317
(handler-bind
318-
(((and condition (not (or monitor-error
319-
cli-parsing-error
320-
source-definition-error
321-
regression-test-error)))
322-
#'(lambda (condition)
323-
(format *error-output* "KABOOM!~%")
324-
(format *error-output* "FATAL error: ~a~%~a~%~%"
325-
condition
326-
(print-backtrace condition debug)))))
318+
(((and serious-condition (not (or monitor-error
319+
cli-parsing-error
320+
source-definition-error
321+
regression-test-error)))
322+
#'(lambda (condition)
323+
(format *error-output* "KABOOM!~%")
324+
(format *error-output* "~a: ~a~%~a~%~%"
325+
(class-name (class-of condition))
326+
condition
327+
(print-backtrace condition debug)))))
327328

328329
(with-monitor ()
329330
;; tell the user where to look for interesting things
@@ -385,7 +386,7 @@
385386
(format *error-output* "~a~%" c)
386387
(uiop:quit +os-code-error+))
387388

388-
(condition (c)
389+
(serious-condition (c)
389390
(format *error-output* "~%What I am doing here?~%~%")
390391
(format *error-output* "~a~%~%" c)
391392
(uiop:quit +os-code-error+)))))

0 commit comments

Comments
 (0)