fix NoMethodError on write error