Handling an error from close is a bad way to handle the error, because the file is already closed, so you are pretty much stuffed.
You want to call fsync() instead, and grab the error there, which will prevent you from being able to get an error from close() - see "Dealing with error returns from close()" in https://www.man7.org/linux/man-pages/man2/close.2.html
If you get it on close, you have ~no idea which operation failed.
Obviously doing it on the operation allows you to wrap it up in the handling of the operation and allows you to do RAII (or DIRR as it probably should be known).
(The EBADF option is nonsense in a properly developed application, and should cause a panic. The EINTR position is just a mess.)
Error-on-close is basically another form of error-on-destruct, and like you say it doesn't make much sense to raise an error about something that no longer exists. It's not RAII that's wrong here, but the messy semantics of close() and its use as an ad-hoc asynchronous error reporting mechanism.
You want to call fsync() instead, and grab the error there, which will prevent you from being able to get an error from close() - see "Dealing with error returns from close()" in https://www.man7.org/linux/man-pages/man2/close.2.html
If you get it on close, you have ~no idea which operation failed.
Obviously doing it on the operation allows you to wrap it up in the handling of the operation and allows you to do RAII (or DIRR as it probably should be known).
(The EBADF option is nonsense in a properly developed application, and should cause a panic. The EINTR position is just a mess.)