|
6 | 6 | :kiln/hot-reload |
7 | 7 | :kiln/script-cache |
8 | 8 | :with-user-abort) |
9 | | - (:import-from :clingon) |
10 | 9 | (:import-from :cmd) |
11 | 10 | (:import-from :kiln/user) |
12 | 11 | (:import-from :uiop) |
13 | 12 | (:export |
14 | 13 | :*entry-point* |
15 | 14 | :dispatch |
| 15 | + :error-exit-code |
16 | 16 | :exec |
17 | 17 | :invoke-entry-point |
18 | 18 | :invoke-script |
19 | 19 | :missing-main |
20 | 20 | :no-such-package |
21 | 21 | :no-such-script |
| 22 | + :print-error-and-backtrace |
22 | 23 | :script-error |
23 | 24 | :script-error.name |
24 | 25 | :script-package-error |
|
163 | 164 | "If there is an unhandled subprocess error, return with its exit code." |
164 | 165 | (or (uiop:subprocess-error-code e) |
165 | 166 | (call-next-method))) |
166 | | - (:method ((e clingon:exit-error)) |
167 | | - (clingon:exit-error-code e)) |
168 | 167 | ;; See https://tldp.org/LDP/abs/html/exitcodes.html |
169 | 168 | (:method ((e no-arguments)) +ex-usage+) |
170 | 169 | (:method ((e no-such-package)) 126) ;command cannot execute |
@@ -254,6 +253,17 @@ Default entry point." |
254 | 253 | (dispatch/shebang script-name script-args) |
255 | 254 | (dispatch/package script-name script-args)))))))) |
256 | 255 |
|
| 256 | +(defgeneric print-error-and-backtrace (e) |
| 257 | + (:documentation "Print an error") |
| 258 | + (:method ((e t)) |
| 259 | + (let* ((c (type-of e))) |
| 260 | + (format *error-output* "~&~@(~a~): " |
| 261 | + (substitute #\Space #\- (string c)))) |
| 262 | + (print-error e *error-output*) |
| 263 | + (format *error-output* "~&") |
| 264 | + (when (backtrace?) |
| 265 | + (uiop:print-backtrace :condition e :stream *error-output*)))) |
| 266 | + |
257 | 267 | (defun invoke-entry-point () |
258 | 268 | "Invoke the function set as `*entry-point*' in an appropriate dynamic |
259 | 269 | environment. |
@@ -281,15 +291,7 @@ handlers to give the desired behavior for scripting." |
281 | 291 | (unless (zerop exit-code) |
282 | 292 | (kill-other-threads)) |
283 | 293 | ;; NB `uiop:quit' implicitly finishes outputs. |
284 | | - (uiop:quit exit-code)) |
285 | | - (print-error-and-backtrace (e) |
286 | | - (let* ((c (type-of e))) |
287 | | - (format *error-output* "~&~@(~a~): " |
288 | | - (substitute #\Space #\- (string c)))) |
289 | | - (print-error e *error-output*) |
290 | | - (format *error-output* "~&") |
291 | | - (when (backtrace?) |
292 | | - (uiop:print-backtrace :condition e :stream *error-output*)))) |
| 294 | + (uiop:quit exit-code))) |
293 | 295 | (handler-bind (#+sbcl ((or style-warning sb-ext:compiler-note) #'muffle-warning) |
294 | 296 | ((or #+sbcl sb-int:broken-pipe end-of-file) |
295 | 297 | (lambda (e) |
@@ -317,9 +319,9 @@ handlers to give the desired behavior for scripting." |
317 | 319 | (when (repl-on-error?) |
318 | 320 | (invoke-script "repl"))))) |
319 | 321 | (with-user-abort |
320 | | - (funcall |
321 | | - (catch 'exec |
322 | | - (constantly (funcall *entry-point*)))) |
| 322 | + (funcall |
| 323 | + (catch 'exec |
| 324 | + (constantly (funcall *entry-point*)))) |
323 | 325 | (quit (exit-code)))) |
324 | 326 | (user-abort (e) |
325 | 327 | (when (backtrace?) |
|
0 commit comments