feat(prebuild): add err reporting to builder & directive tasks.

This commit is contained in:
Alexandre Pujol 2024-05-25 22:30:20 +01:00
parent 865ce4c66b
commit 02e3334949
No known key found for this signature in database
GPG key ID: C5469996F0DF68EC
19 changed files with 108 additions and 53 deletions

View file

@ -26,7 +26,7 @@ var (
// Main directive interface
type Directive interface {
cfg.BaseInterface
Apply(opt *Option, profile string) string
Apply(opt *Option, profile string) (string, error)
}
// Directive options
@ -65,14 +65,18 @@ func RegisterDirective(d Directive) {
Directives[d.Name()] = d
}
func Run(file *paths.Path, profile string) string {
func Run(file *paths.Path, profile string) (string, error) {
var err error
for _, match := range regDirective.FindAllStringSubmatch(profile, -1) {
opt := NewOption(file, match)
drtv, ok := Directives[opt.Name]
if !ok {
panic(fmt.Sprintf("Unknown directive: %s", opt.Name))
return "", fmt.Errorf("Unknown directive: %s", opt.Name)
}
profile, err = drtv.Apply(opt, profile)
if err != nil {
return "", err
}
profile = drtv.Apply(opt, profile)
}
return profile
return profile, nil
}