depfile helper: check errors on writing .d files

Closes #492 and #493.