Skip to content

Commit

Permalink
store errno in SIMPLE-FILE-ERROR conditions
Browse files Browse the repository at this point in the history
CCL signals SIMPLE-FILE-ERROR conditions for all file-related errors, but they
do not contain any information to programmatically distinguish what the error
actually is.

The most basic use case is the ability to detect that opening a file failed
because it does not exist. Without this patch, it is impossible to make the
difference between a file-not-found error and for example an IO error.
  • Loading branch information
galdor committed Feb 21, 2023
1 parent ff51228 commit 1f276c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions level-1/l1-error-signal.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
(format-string (if errargs
(format nil "~a : ~a" error-string "~s")
error-string)))
(%err-disp-common nil err-type format-string errargs frame-ptr)))
(%err-disp-common errno err-type format-string errargs frame-ptr)))


(defun %err-disp-internal (err-num errargs frame-ptr)
Expand Down Expand Up @@ -87,7 +87,8 @@
(simple-file-error (make-condition condition-name
:pathname (car errargs)
:error-type format-string
:format-arguments (cdr errargs)))
:format-arguments (cdr errargs)
:errno err-num))
(undefined-function (make-condition condition-name
:name (car errargs)))
(call-special-operator-or-macro
Expand Down
4 changes: 3 additions & 1 deletion level-1/l1-error-system.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,9 @@
(file-error-pathname c)))))

(define-condition simple-file-error (simple-condition file-error)
()
((errno
:initarg :errno
:reader simple-file-error-errno))
(:report (lambda (c s)
(apply #'format s (slot-value c 'error-type)
(file-error-pathname c)
Expand Down

0 comments on commit 1f276c7

Please sign in to comment.