bah, some uninformed error handling. WIP

This commit is contained in:
Jan Nieuwenhuizen 2018-07-14 17:18:18 +02:00
parent 870fc792d7
commit 0408463a13
1 changed files with 17 additions and 2 deletions

View File

@ -294,10 +294,21 @@
(((and (? string?) command) args ...) (values command args))
(_ (values #f #f)))
(let ((program (and command
(PATH-search-path command))))
(cond ((string-prefix? "/" command)
(when (not (file-exists? command))
(format (current-error-port) "gash: ~a: no such file or directory\n" command))
command)
(else (PATH-search-path command))))))
;; FIXME: find some generic strerror/errno way: what about permissions and stuff?
;; after calling system* we're too late for that?
(when (not program)
(format (current-error-port) "gash: ~a: command not found\n" command))
(when (> %debug-level 0)
(format (current-error-port) "command ~a => ~s ~s\n" (or program 'builtin) command args))
(cond ((and program (not prefer-builtin?)) #f)
(cond ((and program (not prefer-builtin?))
(when (not (access? program X_OK))
(format (current-error-port) "gash: ~a: permission denied\n" command))
#f)
((and command (assoc-ref %builtin-commands command))
=>
(lambda (command)
@ -358,6 +369,10 @@
(cut apply (compose (lambda (status)
((compose (cut assignment "?" <>) number->string) status)
status)
(lambda (status)
(when (not (zero? status))
(format (current-error-port) "*****gash: ~a: ~a" (car command) (strerror status)))
status)
status:exit-val
system*) command))
(else (lambda () #t))))