If there is an error, file will be `nil`. We should check the returned error before deferring file `Close()`.