backend/remote-state/gcloud: Handle errors returned by Write(), too.

Many GCS errors are returned by Close(), but not all.
This commit is contained in:
Florian Forster 2017-09-07 13:52:51 +02:00 committed by James Bardin
parent 1ee194986d
commit f33005faba
1 changed files with 7 additions and 5 deletions

View File

@ -50,11 +50,13 @@ func (c *RemoteClient) Get() (payload *remote.Payload, err error) {
}
func (c *RemoteClient) Put(data []byte) error {
stateFileWriter := c.stateFile().NewWriter(c.storageContext)
stateFileWriter.Write(data)
err := stateFileWriter.Close()
err := func() error {
stateFileWriter := c.stateFile().NewWriter(c.storageContext)
if _, err := stateFileWriter.Write(data); err != nil {
return err
}
return stateFileWriter.Close()
}()
if err != nil {
return fmt.Errorf("Failed to upload state to %v: %v", c.stateFileURL(), err)
}