diff --git a/src/api.lisp b/src/api.lisp index 9a5b040..44e652c 100644 --- a/src/api.lisp +++ b/src/api.lisp @@ -157,12 +157,12 @@ Parameters here are meant to be already parsed, see parse-cli-optargs." (typecase source (function (list source)) - (list (list (compile nil source))) + (list (list (compile-lisp-command source))) - (pathname (mapcar (lambda (expr) (compile nil expr)) + (pathname (mapcar #'compile-lisp-command (parse-commands-from-file source))) - (t (mapcar (lambda (expr) (compile nil expr)) + (t (mapcar #'compile-lisp-command (if (probe-file source) (parse-commands-from-file source) (parse-commands source))))))) @@ -172,6 +172,30 @@ Parameters here are meant to be already parsed, see parse-cli-optargs." :do (when flush-summary (flush-summary :reset t)))))) +(defun compile-lisp-command (source) + "SOURCE must be lisp source code, a list form." + (let (function warnings-p failure-p notes) + ;; capture the compiler notes and warnings + (setf notes + (with-output-to-string (stream) + (let ((*standard-output* stream) + (*error-output* stream) + (*trace-output* stream)) + (with-compilation-unit (:override t) + (setf (values function warnings-p failure-p) + (compile nil source)))))) + + ;; log the captured compiler output at the DEBUG level + (when (and notes (string/= notes "")) + (let ((pp-source (with-output-to-string (s) (pprint source s)))) + (log-message :debug "While compiling:~%~a~%~a" pp-source notes))) + + ;; and signal an error if we failed to compile our lisp code + (cond + (failure-p (error "Failed to compile code: ~a~%~a" source notes)) + (warnings-p function) + (t function)))) + ;;; ;;; Main API to use from outside of pgloader. diff --git a/src/main.lisp b/src/main.lisp index 8d63e35..24020ed 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -315,15 +315,16 @@ ;; meaningful backtrace to the user in case of unexpected ;; conditions being signaled. (handler-bind - (((and condition (not (or monitor-error - cli-parsing-error - source-definition-error - regression-test-error))) - #'(lambda (condition) - (format *error-output* "KABOOM!~%") - (format *error-output* "FATAL error: ~a~%~a~%~%" - condition - (print-backtrace condition debug))))) + (((and serious-condition (not (or monitor-error + cli-parsing-error + source-definition-error + regression-test-error))) + #'(lambda (condition) + (format *error-output* "KABOOM!~%") + (format *error-output* "~a: ~a~%~a~%~%" + (class-name (class-of condition)) + condition + (print-backtrace condition debug))))) (with-monitor () ;; tell the user where to look for interesting things @@ -385,7 +386,7 @@ (format *error-output* "~a~%" c) (uiop:quit +os-code-error+)) - (condition (c) + (serious-condition (c) (format *error-output* "~%What I am doing here?~%~%") (format *error-output* "~a~%~%" c) (uiop:quit +os-code-error+)))))