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:
commit
5c2aedc694
1 changed files with 5 additions and 4 deletions
|
@ -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") ||
|
||||||
|
|
Loading…
Reference in a new issue