Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: include action ID in action error string #539

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions hcloud/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func (e ActionError) Action() *Action {
}

func (e ActionError) Error() string {
action := e.Action()
if action != nil {
// For easier debugging, the error string contains the Action ID.
return fmt.Sprintf("%s (%s, %d)", e.Message, e.Code, action.ID)
}
return fmt.Sprintf("%s (%s)", e.Message, e.Code)
}

Expand Down
13 changes: 13 additions & 0 deletions hcloud/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,22 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"

"github.com/hetznercloud/hcloud-go/v2/hcloud/schema"
)

func TestActionError(t *testing.T) {
assert.Equal(t,
"action failed (failed)",
ActionError{Code: "failed", Message: "action failed"}.Error(),
)
assert.Equal(t,
"action failed (failed, 12345)",
ActionError{Code: "failed", Message: "action failed", action: &Action{ID: 12345}}.Error(),
)
}

func TestActionClientGetByID(t *testing.T) {
env := newTestEnv()
defer env.Teardown()
Expand Down
Loading