Skip to content

Commit 013477f

Browse files
authored
fix: improve error message format with correlation id (#430)
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) ```
1 parent 94229eb commit 013477f

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

hcloud/error.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (e Error) Error() string {
104104
correlationID := resp.internalCorrelationID()
105105
if correlationID != "" {
106106
// For easier debugging, the error string contains the Correlation ID of the response.
107-
return fmt.Sprintf("%s (%s) (Correlation ID: %s)", e.Message, e.Code, correlationID)
107+
return fmt.Sprintf("%s (%s, %s)", e.Message, e.Code, correlationID)
108108
}
109109
}
110110
return fmt.Sprintf("%s (%s)", e.Message, e.Code)

hcloud/error_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ func TestError_Error(t *testing.T) {
3939
Header: func() http.Header {
4040
headers := http.Header{}
4141
// [http.Header] requires normalized header names, easiest to do by using the Set method
42-
headers.Set("X-Correlation-ID", "foobar")
42+
headers.Set("X-Correlation-ID", "d5064a1f0bb9de4b")
4343
return headers
4444
}(),
4545
},
4646
},
4747
},
48-
want: "Creating image failed because of an unknown error. (unknown_error) (Correlation ID: foobar)",
48+
want: "Creating image failed because of an unknown error. (unknown_error, d5064a1f0bb9de4b)",
4949
},
5050
{
5151
name: "internal server error without correlation id",

0 commit comments

Comments
 (0)