From b0edcf78a4b4b1d2e761b11d2f0930243f39f2f6 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Fri, 31 May 2024 21:40:05 -0500 Subject: [PATCH] Fix UNIX cli error-handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … I made a silly, brainless mistake here. :P --- src/unix.lisp | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/unix.lisp b/src/unix.lisp index 9a43e5e..2eaa2c6 100644 --- a/src/unix.lisp +++ b/src/unix.lisp @@ -36,21 +36,22 @@ ;; nil → nil (defun main () "Actual invocation of the program. This is what you should set as :toplevel." - (error-print - 99 "" - (multiple-value-bind (opts free) (opts:get-opts) - (when-opt opts :help (help)) - (let* ((input-stream (choose-input-stream (car free))) - (url-base (or (getf opts :url-base) (getf opts :download-dir) "mirror/")) - (download-dir (or (getf opts :download-dir) url-base))) - (when (not input-stream) - (error-print 1 "No HTML file provided. See --help for more information.")) - (format - 't - (mirror-img:mirror-img - input-stream - download-dir - :url-dir url-base)))))) + (handler-case + (multiple-value-bind (opts free) (opts:get-opts) + (when-opt opts :help (help)) + (let* ((input-stream (choose-input-stream (car free))) + (url-base (or (getf opts :url-base) (getf opts :download-dir) "mirror/")) + (download-dir (or (getf opts :download-dir) url-base))) + (when (not input-stream) + (error-print 1 "No HTML file provided. See --help for more information.")) + (format + 't + (mirror-img:mirror-img + input-stream + download-dir + :url-dir url-base)))) + (error (c) + (error-print 99 nil c)))) (opts:define-opts (:name :help @@ -69,6 +70,10 @@ (error (c) (error-print 11 "Could not access or create directory." c)))))) + + +;;; Output +;;; ———————————————————————————————————————— ;; number stream → nil (defun help (&optional (exit-code 0) (stream *standard-output*)) "Prints help message and dies." @@ -82,7 +87,7 @@ ;; number string condition → nil (defun error-print (exit-code &optional message condition) "Print an error-message and exit." - (format *error-output* "~@[~A~%~]~@[~A~%~]" message condition) + (format *error-output* "~@[~A~%~]~@[Error: ~A~%~]" message condition) (unix-opts:exit exit-code))