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

refactor(sdk): return error messages on ascode import #6165

Merged
merged 1 commit into from
May 9, 2022
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
2 changes: 1 addition & 1 deletion cli/cdsctl/workflow_transform_as_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func workflowTransformAsCodeRun(v cli.Values) (interface{}, error) {
return nil, err
}
if w.FromRepository != "" {
return nil, sdk.ErrWorkflowAlreadyAsCode
return nil, sdk.WithStack(sdk.ErrWorkflowAlreadyAsCode)
}

noInteractive := v.GetBool("no-interactive")
Expand Down
2 changes: 1 addition & 1 deletion engine/api/application/application_vunerability.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func LoadVulnerability(db gorp.SqlExecutor, appID int64, vulnID int64) (sdk.Vuln
if err != sql.ErrNoRows {
return sdk.Vulnerability{}, sdk.WrapError(err, "unable to load vulnerability %d for application %d", vulnID, appID)
}
return sdk.Vulnerability{}, sdk.ErrNotFound
return sdk.Vulnerability{}, sdk.WithStack(sdk.ErrNotFound)
}
return sdk.Vulnerability(dbVuln), nil
}
Expand Down
2 changes: 1 addition & 1 deletion engine/api/application_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (api *API) postApplicationImportHandler() service.Handler {
return globalError
}
sdkErr := sdk.ExtractHTTPError(globalError)
return service.WriteJSON(w, append(msgListString, sdkErr.Message), sdkErr.Status)
return service.WriteJSON(w, append(msgListString, sdkErr.Error()), sdkErr.Status)
}

if err := tx.Commit(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion engine/api/environment_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (api *API) postEnvironmentImportHandler() service.Handler {
return globalError
}
sdkErr := sdk.ExtractHTTPError(globalError)
return service.WriteJSON(w, append(msgListString, sdkErr.Message), sdkErr.Status)
return service.WriteJSON(w, append(msgListString, sdkErr.Error()), sdkErr.Status)
}

if err := tx.Commit(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion engine/api/keys/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func Parse(ctx context.Context, db gorp.SqlExecutor, projID int64, kname string,
}
k.Public = string(pubBytes)
default:
return nil, sdk.ErrUnknownKeyType
return nil, sdk.WithStack(sdk.ErrUnknownKeyType)
}
} else if kval.Regen == nil || *kval.Regen == true {
ktemp, err := GenerateKey(kname, k.Type)
Expand Down
2 changes: 1 addition & 1 deletion engine/api/pipeline/pipeline_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func ParseAndImport(ctx context.Context, db gorp.SqlExecutor, cache cache.Store,

var globalError error
if exist && !opts.Force {
return pip, nil, sdk.ErrPipelineAlreadyExists
return pip, nil, sdk.WithStack(sdk.ErrPipelineAlreadyExists)
} else if exist {
globalError = ImportUpdate(ctx, db, proj, pip, msgChan, opts)
} else {
Expand Down
2 changes: 1 addition & 1 deletion engine/api/pipeline_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (api *API) importPipelineHandler() service.Handler {
return globalError
}
sdkErr := sdk.ExtractHTTPError(globalError)
return service.WriteJSON(w, append(msgListString, sdkErr.Message), sdkErr.Status)
return service.WriteJSON(w, append(msgListString, sdkErr.Error()), sdkErr.Status)
}

if err := tx.Commit(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion engine/api/workflow_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (api *API) postWorkflowImportHandler() service.Handler {
if globalError != nil {
if len(msgListString) != 0 {
sdkErr := sdk.ExtractHTTPError(globalError)
return service.WriteJSON(w, append(msgListString, sdkErr.Message), sdkErr.Status)
return service.WriteJSON(w, append(msgListString, sdkErr.Error()), sdkErr.Status)
}
return sdk.WrapError(globalError, "Unable to import workflow %s", ew.GetName())
}
Expand Down
18 changes: 3 additions & 15 deletions sdk/cdsclient/client_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,27 @@ func (c *client) PipelineImport(projectKey string, content io.Reader, mods ...Re
url := fmt.Sprintf("/project/%s/import/pipeline", projectKey)

btes, _, _, err := c.Request(context.Background(), "POST", url, content, mods...)
if err != nil {
return nil, err
}

messages := []string{}
_ = sdk.JSONUnmarshal(btes, &messages)
return messages, nil
return messages, err
}

func (c *client) ApplicationImport(projectKey string, content io.Reader, mods ...RequestModifier) ([]string, error) {
url := fmt.Sprintf("/project/%s/import/application", projectKey)

btes, _, _, err := c.Request(context.Background(), "POST", url, content, mods...)
if err != nil {
return nil, err
}

messages := []string{}
_ = sdk.JSONUnmarshal(btes, &messages)
return messages, nil
return messages, err
}

func (c *client) EnvironmentImport(projectKey string, content io.Reader, mods ...RequestModifier) ([]string, error) {
url := fmt.Sprintf("/project/%s/import/environment", projectKey)

btes, _, _, err := c.Request(context.Background(), "POST", url, content, mods...)
if err != nil {
return nil, err
}

messages := []string{}
_ = sdk.JSONUnmarshal(btes, &messages)
return messages, nil
return messages, err
}

// WorkerModelImport import a worker model via as code
Expand Down