To help understand hard-to-replicate failures, add an option to always generate a debug log but to erase it as a final step if an operation succeeds. If an operation fails, keep the log and print a message pointing to it.
Maybe, save such logs somewhere under .git/annex and have a command to upload them (over https and encrypted with @joeyh's key?) to some server where they can be examined.
I'm doubtful about this:
When testing a new version of git-annex-remote-googledrive, I often use a wrapper script like this:
It's good enough for me in those cases. Changing the first line of the function to something like this
log_file=$(umask 077; mktemp /tmp/annex.debug.XXX.log" 2>/dev/null)
would help against accumulating logs.