Merge pull request #3095 from drone/defect/template-not-found-handling

handle error properly if template doesn't exist in the db
This commit is contained in:
TP Honey 2021-06-17 10:48:57 +01:00 committed by GitHub
commit 5c2aedc694
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,6 +18,7 @@ package converter
import ( import (
"context" "context"
"database/sql"
"errors" "errors"
"regexp" "regexp"
"strings" "strings"
@ -63,12 +64,12 @@ func (p *templatePlugin) Convert(ctx context.Context, req *core.ConvertArgs) (*c
} }
// get template from db // get template from db
template, err := p.templateStore.FindName(ctx, templateArgs.Load, req.Repo.Namespace) template, err := p.templateStore.FindName(ctx, templateArgs.Load, req.Repo.Namespace)
if err != nil { if err == sql.ErrNoRows {
return nil, nil
}
if template == nil {
return nil, ErrTemplateNotFound return nil, ErrTemplateNotFound
} }
if err != nil {
return nil, err
}
// Check if file is of type Starlark // Check if file is of type Starlark
if strings.HasSuffix(templateArgs.Load, ".script") || if strings.HasSuffix(templateArgs.Load, ".script") ||
strings.HasSuffix(templateArgs.Load, ".star") || strings.HasSuffix(templateArgs.Load, ".star") ||