Skip to content

Commit

Permalink
fix(api): avoid panic if app does not exist (#4963)
Browse files Browse the repository at this point in the history
* fix(api): avoid panic if app does not exist

/usr/local/go/src/runtime/panic.go:679 +0x1b2
github.com/ovh/cds/engine/api.(*API).postResyncPRAsCodeHandler.func1(0x3110ce0, 0xc002caa1e0, 0x31055a0, 0xc002362440, 0xc001eece00, 0xc001358d90, 0x3110ce0)
	/tmp/QnVpbGQgYW5kIFBhY2thZ2UgQWxs/run/engine/api/ascode.go:199 +0x5eb

Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault committed Feb 6, 2020
1 parent 7b7ced5 commit 1f44f4a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions engine/api/ascode.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,19 @@ func (api *API) postResyncPRAsCodeHandler() service.Handler {
if err != nil {
return err
}
if len(apps) == 0 {
return sdk.WrapError(sdk.ErrApplicationNotFound, "unable to load application as code key:%s fromRepo:%s", key, fromRepo)
}
app = &apps[0]
} else {
var err error
app, err = application.LoadByName(api.mustDB(), api.Cache, key, appName)
if err != nil {
return err
}
if app == nil {
return sdk.WrapError(sdk.ErrApplicationNotFound, "unable to load application %s", appName)
}
}

if _, _, err := sync.SyncAsCodeEvent(ctx, api.mustDB(), api.Cache, proj, app, getAPIConsumer(ctx).AuthentifiedUser); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion sdk/workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (r *WorkflowRun) Tag(tag, value string) bool {
return false
}

// TagExists return true if tag already exits
// TagExists returns true if tag already exists
func (r *WorkflowRun) TagExists(tag string) bool {
for i := range r.Tags {
if r.Tags[i].Tag == tag {
Expand Down
4 changes: 3 additions & 1 deletion ui/src/app/service/ascode/ascode.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export class AscodeService {
if (repo) {
params = params.append('repo', repo);
}
params = params.append('appName', appName);
if (appName) {
params = params.append('appName', appName);
}

return this._http.post<boolean>(`/project/${projectKey}/ascode/events/resync`, null, {params})
.map(() => {
Expand Down

0 comments on commit 1f44f4a

Please sign in to comment.