Re: Clearing up confusion, and Windows errors as POSIX errno's Lassi Kortela 14 Aug 2020 15:27 UTC
Hmm, how about this: (make-foreign-error 'set 'windows 'number 2 'name 'ERROR_FILE_NOT_FOUND 'message "File not found" 'errno-name 'ENOENT) ; <--------- The 'errno-name property could be a generic one for mapping the native errors from various systems into equivalent errnos, on a close-enough basis. For example, any kind of "file not found" error could be mapped to 'ENOENT. Using ('set 'errno 'name ENOENT 'number 2) is a bit deceptive when we know the error is from the Windows API and know the GetLastError() code. We should return the native Windows code instead. But if we add an extra 'errno-name that should give the best of both worlds. Perhaps 'errno-equivalent, 'errno-equiv or a simple 'errno as Harold suggested would be a better name for the property. Users who care about portable code would be writing code like this: (define (read-symlink-if-exists path) (guard (err ((and (foreign-status? err) (eq? 'ENOENT (foreign-status-ref err 'errno))) #f)) (read-symlink path))) That doesn't look bad to me, especially given that Windows could be supported with the same code while preserving native WinAPI error information.