Clozure / ccl

Clozure Common Lisp
http://ccl.clozure.com
Apache License 2.0
841 stars 105 forks source link

store errno in SIMPLE-FILE-ERROR conditions #442

Open galdor opened 1 year ago

galdor commented 1 year ago

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 did not exist. Without this patch, it is impossible to make the difference between a file-not-found error and, for example, an IO error.

I originally wanted to introduced a new FILE-DOES-NOT-EXIST condition inheriting from SIMPLE-FILE-ERROR as SBCL does with SB-EXT:FILE-DOES-NOT-EXIST, but this would require seriously reworking the whole %ERR-DISP-COMMON thing, and I honestly have no idea where to start. Storing errno into the file error makes sense. Even if it is very low level, it provides the necessary information so that a caller can decide how to handle it, without changing any existing API.

galdor commented 1 year ago

Btw I just realized that SIMPLE-FILE-ERROR was not exported. Would it be ok to export it with SIMPLE-FILE-ERROR-ERRNO, and if yes where should the export be?

xrme commented 1 year ago

https://github.com/Clozure/ccl/issues/364 may also be in this area

galdor commented 1 year ago

Indeed, it seems useful. But there is not much I can do about it, I do not have write access ;)

xrme commented 1 year ago

I hate to discourage this, but it feels to me that this (expose errno in simple-file-error) is not the right way to go.

You said that you really wanted a file-does-not-exist error, and I'd rather see us pursue that. I see that there is a lot of hair around %err-disp and friends, and I don't blame you for wanting to look the other way.

galdor commented 1 year ago

That would be better indeed; but in that case, I would simply ignore %ERR-DISP and signal the right condition directly at the source. I suspect %ERR-DISP, which seems to be only used to dispatch to the "right" condition type, could be removed altogether.