diff --git a/sexc.scm b/sexc.scm index 558d5f0c..e2a9c71d 100644 --- a/sexc.scm +++ b/sexc.scm @@ -268,7 +268,29 @@ status, which is ours to pass on." ;; every module (list (closure-env-declaration)))) +;;; An error is told by its message, file:line first where it has one. +;;; CHICKEN's call history after it is for working on sexc itself, and +;;; SEXC_DEBUG asks for it (define (main) + (if (get-environment-variable "SEXC_DEBUG") + (run) + (handle-exceptions exn + (let ((message ((condition-property-accessor 'exn 'message #f) exn)) + (port (current-error-port))) + (unless message (abort exn)) + (display "Error: " port) + (display message port) + (let ((arguments + ((condition-property-accessor 'exn 'arguments (list)) exn))) + (unless (null? arguments) + (display ":" port) + (for-each (lambda (a) (display " " port) (write a port)) + arguments))) + (newline port) + (exit 70)) + (run)))) + +(define (run) (let* ((argv (command-line-arguments)) (raw-args (spell-stdout-output (args-before-separator argv))) (cc-args (args-after-separator argv)) @@ -287,6 +309,8 @@ status, which is ours to pass on." (error "-o - is stdout, which takes only -C, -m or --public-interface")) (when (same-file? input output) (error "-o names the input, and would overwrite its source" input)) + (when (and (string? input) (not (file-exists? input))) + (error (string-append input ": no such file"))) ;; Read time comes before everything, so the features have to be ;; in place before the first form is read (current-features diff --git a/tests/exit-code/check.scm b/tests/exit-code/check.scm index 90307bce..f35035d6 100644 --- a/tests/exit-code/check.scm +++ b/tests/exit-code/check.scm @@ -108,6 +108,25 @@ (test "and the source is as it was" hello-source (call-with-input-file "victim.sex" (lambda (p) (read-string #f p)))) +;;; An error is its message: CHICKEN's call history after it is for +;;; working on sexc itself, and asked for by SEXC_DEBUG +(test-assert "a missing input says so" + (let ((run (sexc-run #f "no-such.sex"))) + (and (not (zero? (car run))) + (substring-index "no-such.sex: no such file" (caddr run)) + (not (substring-index "Call history" (caddr run)))))) +(test-assert "and any error is its message alone" + (let ((run (sexc-run "(fn f () int (return \"\\q\"))" "-C" "-o" "-"))) + (and (= 70 (car run)) + (substring-index "Error: stdin:1: unknown escape" (caddr run)) + (not (substring-index "Call history" (caddr run)))))) +(test-assert "unless the history is asked for" + (begin + (set-environment-variable! "SEXC_DEBUG" "1") + (let ((run (sexc-run "(fn f () int (return \"\\q\"))" "-C" "-o" "-"))) + (unset-environment-variable! "SEXC_DEBUG") + (and (substring-index "Call history" (caddr run)) #t)))) + (delete-directory scratch #t) (test-exit)