check for error from write before doing the commit

Ported from 1.5.x:
8dec4ad62323659e54ec9d3ea76d6df26be36119

Signed-off-by: Rick Mesta <rmesta@us.ibm.com>