From bb1c134b94fc52345f86f8557aee47ac0da0b479 Mon Sep 17 00:00:00 2001 From: Nicolas Vanheuverzwijn Date: Thu, 16 Jun 2022 10:50:51 -0400 Subject: [PATCH] http-backend: http backend lock error return LockError instead of generic error --- internal/backend/remote-state/http/client.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/internal/backend/remote-state/http/client.go b/internal/backend/remote-state/http/client.go index 0aed96886d..71668c0a2d 100644 --- a/internal/backend/remote-state/http/client.go +++ b/internal/backend/remote-state/http/client.go @@ -100,14 +100,23 @@ func (c *httpClient) Lock(info *statemgr.LockInfo) (string, error) { defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { - return "", fmt.Errorf("HTTP remote state already locked, failed to read body") + return "", &statemgr.LockError{ + Info: info, + Err: fmt.Errorf("HTTP remote state already locked, failed to read body"), + } } existing := statemgr.LockInfo{} err = json.Unmarshal(body, &existing) if err != nil { - return "", fmt.Errorf("HTTP remote state already locked, failed to unmarshal body") + return "", &statemgr.LockError{ + Info: info, + Err: fmt.Errorf("HTTP remote state already locked, failed to unmarshal body"), + } + } + return "", &statemgr.LockError{ + Info: info, + Err: fmt.Errorf("HTTP remote state already locked: ID=%s", existing.ID), } - return "", fmt.Errorf("HTTP remote state already locked: ID=%s", existing.ID) default: return "", fmt.Errorf("Unexpected HTTP response code %d", resp.StatusCode) }