Improve error handling for edit and write

Signed-off-by: Casey Dahlin <casey.dahlin@gmail.com>