action.Error

This commit is contained in:
Sebastian Frank 2021-08-12 17:07:56 +02:00
parent 130d4fedc7
commit 1dbb38b822
Signed by: apairon
GPG Key ID: A0E05A8199CE3F57

13
main.go
View File

@ -46,8 +46,9 @@ type ActionConfig struct {
OnSuccess []ActionConfig `yaml:"onSuccess"`
OnError []ActionConfig `yaml:"onError"`
_dirConf *DirectoryConfig
Directory *DirectoryConfig `yaml:"-"`
Parent *ActionConfig `yaml:"-"`
Error error `yaml:"-"`
}
type DirectoryConfig struct {
@ -175,7 +176,7 @@ func startWatcher(directory *DirectoryConfig) {
}
if directory._regex == nil || directory._regexMatches != nil {
for _, action := range directory.Actions {
action._dirConf = directory
action.Directory = directory
contin, _ := runAction(&action, eventInfo, nil)
if !contin {
break
@ -241,10 +242,11 @@ func runAction(action *ActionConfig, eventInfo notify.EventInfo, ctx actionCtx)
if err != nil {
add2Ctx(action, ctx, "error", err.Error())
action.Error = err
log.Printf("path: %s; action: %s; error %s", eventInfo.Path(), action.Id, err)
for _, aE := range action.OnError {
aE._dirConf = action._dirConf
aE.Directory = action.Directory
aE.Parent = action
_c, _ := runAction(&aE, eventInfo, ctx)
contin = contin && _c
@ -254,7 +256,7 @@ func runAction(action *ActionConfig, eventInfo notify.EventInfo, ctx actionCtx)
}
} else {
for _, aS := range action.OnSuccess {
aS._dirConf = action._dirConf
aS.Directory = action.Directory
aS.Parent = action
_c, errS := runAction(&aS, eventInfo, ctx)
contin = contin && _c
@ -453,7 +455,8 @@ func tpl2String(tpl string, action *ActionConfig, eventInfo notify.EventInfo, ct
"filename": filepath.Base(p),
"event": eventInfo.Event().String(),
"action": action,
"regexMatches": action._dirConf._regexMatches,
"directory": action.Directory,
"regexMatches": action.Directory._regexMatches,
"context": ctx,
})
}