[DGD] Is Running Atomically.

Gary gary at mups.co.uk
Sat Sep 24 22:15:55 CEST 2016


On 24/09/16 20:07, bart at wotf.org wrote:
> If you just want to deal with the file writes in the logging code, you could
> also simply catch() the write, and see what the error is, it will also tell
> you you are running atomic so you can respond to that.
> 
> What I described is much more generic (without it requiring some dummy file to
> try writing to as a test)
> 

I had considered using catch, but (and this could just be due to a lack
of knowledge of DGD/its error handling on my part) that seemed to hide
non atomic errors in write_file.

Is there a way to know that the caught part of a catch triggered due to
an atomic error rather than any other error that write_file (or other
code) may raise?

At the moment in my LOGD write_log function I'm doing (amongst other code)

   if (! running_atomically())
      write_file(SYSTEM_LOG_FILE, message);
   else
      driver->message(message);

The LOGD is currently quite bare bones and the above is just to ensure
log calls (mostly debug logs) are reported at least somewhere if they're
made during an atomic operation.

Whilst I can change that to:

   catch {
      write_file(SYSTEM_LOG_FILE, message);
   } : {
      driver->message(message);
   }

Is there any way to know what error has been caught? Then the
redirection of message to stderr via the driver can be done just for
failure to write during an atomic function.

As in the case of other errors, for example if write_file can fail due
to some disk i/o issue? I'd want to be reporting that specific error via
the driver rather than (or along with) the original log message. Or
allowing the error to go uncaught to later be handled by atomic_error in
the errord.

Is that possible?

Regards,

Gary





More information about the DGD mailing list