extracted methods write_error and write_error_line