cleanup: consolidate write_nonblock error handling