Skip to content
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
6 changes: 5 additions & 1 deletion addon/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Tackle hub/addon integration.
package addon

import (
"fmt"
"os"

logapi "github.com/go-logr/logr"
Expand Down Expand Up @@ -80,6 +81,8 @@ type Adapter struct {
Task
// Log API.
Log logapi.Logger
// Wrap error API.
Wrap func(error, ...any) error
// Settings API.
Setting Setting
// Schema API
Expand Down Expand Up @@ -125,7 +128,7 @@ func (h *Adapter) Run(addon func() error) {
if pErr, cast := r.(error); cast {
err = pErr
} else {
panic(r)
err = fmt.Errorf("%#v", r)
}
}
if err != nil {
Expand Down Expand Up @@ -164,6 +167,7 @@ func newAdapter() (adapter *Adapter) {
richClient: richClient,
},
Log: Log,
Wrap: Wrap,
Setting: richClient.Setting,
Schema: richClient.Schema,
Application: richClient.Application,
Expand Down
29 changes: 19 additions & 10 deletions addon/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,20 @@ func (h *Task) Load() {

// Application returns the application associated with the task.
func (h *Task) Application() (r *api.Application, err error) {
appRef := h.task.Application
if appRef == nil {
err = &NotFound{}
ref := h.task.Application
if ref == nil {
err = Wrap(&NotFound{
RestError: ResetError{
Reason: "application not specified."},
})
return
}
r, err = h.richClient.Application.Get(appRef.ID)
r, err = h.richClient.Application.Get(ref.ID)
if err != nil {
return
}
r.Identities = []api.Ref{}
identities, err := h.richClient.Application.Identity(appRef.ID).List()
identities, err := h.richClient.Application.Identity(ref.ID).List()
if err != nil {
return
}
Expand All @@ -60,12 +63,15 @@ func (h *Task) Application() (r *api.Application, err error) {

// Platform returns the platform associated with the task.
func (h *Task) Platform() (r *api.Platform, err error) {
appRef := h.task.Platform
if appRef == nil {
err = &NotFound{}
ref := h.task.Platform
if ref == nil {
err = Wrap(&NotFound{
RestError: ResetError{
Reason: "platform not specified."},
})
return
}
r, err = h.richClient.Platform.Get(appRef.ID)
r, err = h.richClient.Platform.Get(ref.ID)
return
}

Expand All @@ -75,7 +81,10 @@ func (h *Task) Platform() (r *api.Platform, err error) {
func (h *Task) Addon(inject bool) (r *api.Addon, err error) {
name := h.task.Addon
if name == "" {
err = &NotFound{}
err = Wrap(&NotFound{
RestError: ResetError{
Reason: "addon not specified."},
})
return
}
r, err = h.richClient.Addon.Get(name)
Expand Down
Loading