Cleanup some json decoding

Signed-off-by: yottta <andrei.ciobanu@opentofu.org>
This commit is contained in:
yottta 2025-02-21 14:49:22 +02:00
parent 06a173261b
commit c46132cfe2

View File

@ -504,16 +504,8 @@ func (c *RemoteClient) getLockInfoFromS3(ctx context.Context) (*statemgr.LockInf
return nil, err
}
lockContent, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("could not read the content of the lock object %q from bucket %q: %w", c.lockFilePath(), c.bucketName, err)
}
if len(lockContent) == 0 {
return nil, fmt.Errorf("empty lock info found for %q in the s3 bucket: %s", c.lockFilePath(), c.bucketName)
}
lockInfo := &statemgr.LockInfo{}
err = json.Unmarshal(lockContent, lockInfo)
err = json.NewDecoder(resp.Body).Decode(lockInfo)
if err != nil {
return nil, fmt.Errorf("unable to json parse the lock info %q from bucket %q: %w", c.lockFilePath(), c.bucketName, err)
}