emit an error if write is called after closed