Skip to content

Commit

Permalink
fix: improve error message format with correlation id [Backport relea…
Browse files Browse the repository at this point in the history
…se-1.x] (#431)

This improves the format of our error message, as they might be printed
to the users.

Before:
```
hcloud: server name is already used (uniqueness_error) (Correlation ID: d5064a1f0bb9de4b)
```

After:
```
hcloud: server name is already used (uniqueness_error, d5064a1f0bb9de4b)
```

---
Backport 013477f from #430.

BEGIN_COMMIT_OVERRIDE
fix: improve error message format with correlation id
END_COMMIT_OVERRIDE

Co-authored-by: Jonas L <jooola@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and jooola committed May 6, 2024
1 parent 18adaf6 commit 1939cfb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion hcloud/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (e Error) Error() string {
correlationID := resp.internalCorrelationID()
if correlationID != "" {
// For easier debugging, the error string contains the Correlation ID of the response.
return fmt.Sprintf("%s (%s) (Correlation ID: %s)", e.Message, e.Code, correlationID)
return fmt.Sprintf("%s (%s, %s)", e.Message, e.Code, correlationID)
}
}
return fmt.Sprintf("%s (%s)", e.Message, e.Code)
Expand Down
4 changes: 2 additions & 2 deletions hcloud/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ func TestError_Error(t *testing.T) {
Header: func() http.Header {
headers := http.Header{}
// [http.Header] requires normalized header names, easiest to do by using the Set method
headers.Set("X-Correlation-ID", "foobar")
headers.Set("X-Correlation-ID", "d5064a1f0bb9de4b")
return headers
}(),
},
},
},
want: "Creating image failed because of an unknown error. (unknown_error) (Correlation ID: foobar)",
want: "Creating image failed because of an unknown error. (unknown_error, d5064a1f0bb9de4b)",
},
{
name: "internal server error without correlation id",
Expand Down

0 comments on commit 1939cfb

Please sign in to comment.