Skip to content

Commit

Permalink
update error state in vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
linyguo committed Dec 10, 2024
1 parent 16f2bb9 commit 25048ea
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion api/pkg/apis/v1alpha1/providers/target/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ func convertTimeout(ctx context.Context, timeout string) (time.Duration, error)
}
if duration < 0 {
sLog.ErrorfCtx(ctx, " P (Helm Target): Timeout is negative: %s", timeout)
err = v1alpha2.NewCOAError(err, "target provider timeout must be nonegative", v1alpha2.GetComponentPropsFailed)
err = v1alpha2.NewCOAError(err, "target provider timeout can not be negative", v1alpha2.GetComponentPropsFailed)
return 0, err
}
return duration, nil
Expand Down
6 changes: 3 additions & 3 deletions api/pkg/apis/v1alpha1/vendors/catalogs-container-vendor.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (c *CatalogContainersVendor) onCatalogContainers(request v1alpha2.COAReques
if err != nil {
ctLog.ErrorfCtx(ctx, "V (CatalogContainers): onCatalogContainers failed - %s", err.Error())
return observ_utils.CloseSpanWithCOAResponse(span, v1alpha2.COAResponse{
State: v1alpha2.InternalError,
State: v1alpha2.GetErrorState(err),
Body: []byte(err.Error()),
})
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func (c *CatalogContainersVendor) onCatalogContainers(request v1alpha2.COAReques
if err != nil {
ctLog.ErrorfCtx(ctx, "V (CatalogContainers): onCatalogContainers failed - %s", err.Error())
return observ_utils.CloseSpanWithCOAResponse(span, v1alpha2.COAResponse{
State: v1alpha2.InternalError,
State: v1alpha2.GetErrorState(err),
Body: []byte(err.Error()),
})
}
Expand All @@ -151,7 +151,7 @@ func (c *CatalogContainersVendor) onCatalogContainers(request v1alpha2.COAReques
if err != nil {
ctLog.ErrorfCtx(ctx, "V (CatalogContainers): onCatalogContainers failed - %s", err.Error())
return observ_utils.CloseSpanWithCOAResponse(span, v1alpha2.COAResponse{
State: v1alpha2.InternalError,
State: v1alpha2.GetErrorState(err),
Body: []byte(err.Error()),
})
}
Expand Down
14 changes: 7 additions & 7 deletions api/pkg/apis/v1alpha1/vendors/catalogs-vendor.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ func (e *CatalogsVendor) onStatus(request v1alpha2.COARequest) v1alpha2.COARespo
existingCatalog, err := e.CatalogsManager.GetState(rCtx, id, namespace)
if err != nil {
return observ_utils.CloseSpanWithCOAResponse(span, v1alpha2.COAResponse{
State: v1alpha2.InternalError,
State: v1alpha2.GetErrorState(err),
Body: []byte(err.Error()),
})
}
existingCatalog.Spec.Properties["reported"] = components
err = e.CatalogsManager.UpsertState(rCtx, id, existingCatalog)
if err != nil {
return observ_utils.CloseSpanWithCOAResponse(span, v1alpha2.COAResponse{
State: v1alpha2.InternalError,
State: v1alpha2.GetErrorState(err),
Body: []byte(err.Error()),
})
}
Expand Down Expand Up @@ -244,7 +244,7 @@ func (e *CatalogsVendor) onCatalogsGraph(request v1alpha2.COARequest) v1alpha2.C
chains, err := e.CatalogsManager.GetChains(ctx, "config", namespace)
if err != nil {
return observ_utils.CloseSpanWithCOAResponse(span, v1alpha2.COAResponse{
State: v1alpha2.InternalError,
State: v1alpha2.GetErrorState(err),
Body: []byte(err.Error()),
})
}
Expand All @@ -259,7 +259,7 @@ func (e *CatalogsVendor) onCatalogsGraph(request v1alpha2.COARequest) v1alpha2.C
trees, err := e.CatalogsManager.GetTrees(ctx, "asset", namespace)
if err != nil {
return observ_utils.CloseSpanWithCOAResponse(span, v1alpha2.COAResponse{
State: v1alpha2.InternalError,
State: v1alpha2.GetErrorState(err),
Body: []byte(err.Error()),
})
}
Expand Down Expand Up @@ -319,7 +319,7 @@ func (e *CatalogsVendor) onCatalogs(request v1alpha2.COARequest) v1alpha2.COARes
if err != nil {
if !utils.IsNotFound(err) {
return observ_utils.CloseSpanWithCOAResponse(span, v1alpha2.COAResponse{
State: v1alpha2.InternalError,
State: v1alpha2.GetErrorState(err),
Body: []byte(err.Error()),
})
} else {
Expand Down Expand Up @@ -361,7 +361,7 @@ func (e *CatalogsVendor) onCatalogs(request v1alpha2.COARequest) v1alpha2.COARes
err = e.CatalogsManager.UpsertState(ctx, id, catalog)
if err != nil {
return observ_utils.CloseSpanWithCOAResponse(span, v1alpha2.COAResponse{
State: v1alpha2.InternalError,
State: v1alpha2.GetErrorState(err),
Body: []byte(err.Error()),
})
}
Expand All @@ -373,7 +373,7 @@ func (e *CatalogsVendor) onCatalogs(request v1alpha2.COARequest) v1alpha2.COARes
err := e.CatalogsManager.DeleteState(ctx, id, namespace)
if err != nil {
return observ_utils.CloseSpanWithCOAResponse(span, v1alpha2.COAResponse{
State: v1alpha2.InternalError,
State: v1alpha2.GetErrorState(err),
Body: []byte(err.Error()),
})
}
Expand Down
6 changes: 3 additions & 3 deletions api/pkg/apis/v1alpha1/vendors/instances-vendor.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (c *InstancesVendor) onInstances(request v1alpha2.COARequest) v1alpha2.COAR
if err != nil {
iLog.ErrorfCtx(ctx, "V (Instances): onInstances failed - %s", err.Error())
return observ_utils.CloseSpanWithCOAResponse(span, v1alpha2.COAResponse{
State: v1alpha2.InternalError,
State: v1alpha2.GetErrorState(err),
Body: []byte(err.Error()),
})
}
Expand Down Expand Up @@ -174,7 +174,7 @@ func (c *InstancesVendor) onInstances(request v1alpha2.COARequest) v1alpha2.COAR
if err != nil {
iLog.ErrorfCtx(ctx, "V (Instances): onInstances failed - %s", err.Error())
return observ_utils.CloseSpanWithCOAResponse(span, v1alpha2.COAResponse{
State: v1alpha2.InternalError,
State: v1alpha2.GetErrorState(err),
Body: []byte(err.Error()),
})
}
Expand Down Expand Up @@ -219,7 +219,7 @@ func (c *InstancesVendor) onInstances(request v1alpha2.COARequest) v1alpha2.COAR
if err != nil {
iLog.ErrorfCtx(ctx, "V (Instances): onInstances failed - %s", err.Error())
return observ_utils.CloseSpanWithCOAResponse(span, v1alpha2.COAResponse{
State: v1alpha2.InternalError,
State: v1alpha2.GetErrorState(err),
Body: []byte(err.Error()),
})
}
Expand Down
6 changes: 3 additions & 3 deletions api/pkg/apis/v1alpha1/vendors/solutions-container-vendor.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (c *SolutionContainersVendor) onSolutionContainers(request v1alpha2.COARequ
if err != nil {
scLog.ErrorfCtx(ctx, "V (SolutionContainers): onSolutionContainers failed - %s", err.Error())
return observ_utils.CloseSpanWithCOAResponse(span, v1alpha2.COAResponse{
State: v1alpha2.InternalError,
State: v1alpha2.GetErrorState(err),
Body: []byte(err.Error()),
})
}
Expand Down Expand Up @@ -136,7 +136,7 @@ func (c *SolutionContainersVendor) onSolutionContainers(request v1alpha2.COARequ
if err != nil {
scLog.ErrorfCtx(ctx, "V (SolutionContainers): onSolutionContainers failed - %s", err.Error())
return observ_utils.CloseSpanWithCOAResponse(span, v1alpha2.COAResponse{
State: v1alpha2.InternalError,
State: v1alpha2.GetErrorState(err),
Body: []byte(err.Error()),
})
}
Expand All @@ -150,7 +150,7 @@ func (c *SolutionContainersVendor) onSolutionContainers(request v1alpha2.COARequ
if err != nil {
scLog.ErrorfCtx(ctx, "V (SolutionContainers): onSolutionContainers failed - %s", err.Error())
return observ_utils.CloseSpanWithCOAResponse(span, v1alpha2.COAResponse{
State: v1alpha2.InternalError,
State: v1alpha2.GetErrorState(err),
Body: []byte(err.Error()),
})
}
Expand Down
7 changes: 7 additions & 0 deletions coa/pkg/apis/v1alpha2/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ func FromHTTPResponseCode(code int, body []byte) COAError {
}
}

func GetErrorState(err error) State {
if coaErr, ok := err.(COAError); ok {
return coaErr.State
}
return InternalError
}

func NewCOAError(err error, msg string, state State) COAError {
return COAError{
InnerError: err,
Expand Down

0 comments on commit 25048ea

Please sign in to comment.