Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

Commit

Permalink
Fix panic if preRun or postRun is null
Browse files Browse the repository at this point in the history
  • Loading branch information
André Hahn committed Sep 2, 2019
1 parent 226f623 commit ca34e81
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions bot/sequential.go
Expand Up @@ -57,8 +57,8 @@ func NewSequentialBot(
// Initialize initializes the bot
func (b *SequentialBot) Initialize() error {
b.logger.Debug("Initializing bot")
pre := custom.GetPre(b.config, b.spec)
storage, err := pre.Run(b.spec.PreRun.Args)
pre, args := custom.GetPre(b.config, b.spec)
storage, err := pre.Run(args)
if err != nil {
return err
}
Expand Down Expand Up @@ -216,8 +216,8 @@ func (b *SequentialBot) runOperation(op *models.Operation) error {
// Finalize finalizes the bot
func (b *SequentialBot) Finalize() error {
b.logger.Debug("Finalizing bot")
post := custom.GetPost(b.config, b.spec)
if err := post.Run(b.spec.PostRun.Args, b.storage); err != nil {
post, args := custom.GetPost(b.config, b.spec)
if err := post.Run(args, b.storage); err != nil {
return err
}
b.logger.Debugf("Saved storage")
Expand Down
16 changes: 8 additions & 8 deletions custom/custom.go
Expand Up @@ -45,27 +45,27 @@ func (d *DummyPost) Run(args map[string]interface{}, store storage.Storage) erro
}

// GetPre returns the pre operation for the spec, if it exists
func GetPre(config *viper.Viper, spec *models.Spec) PreOperation {
func GetPre(config *viper.Viper, spec *models.Spec) (PreOperation, map[string]interface{}) {
if spec.PreRun == nil {
return &DummyPre{}
return &DummyPre{}, map[string]interface{}{}
}

switch spec.PreRun.Function {
case PreRunFunctionRedis:
return redis.GetPre(config)
return redis.GetPre(config), spec.PreRun.Args
}
return &DummyPre{}
return &DummyPre{}, map[string]interface{}{}
}

// GetPost returns the post operation for the spec, if it exists
func GetPost(config *viper.Viper, spec *models.Spec) PostOperation {
func GetPost(config *viper.Viper, spec *models.Spec) (PostOperation, map[string]interface{}) {
if spec.PostRun == nil {
return &DummyPost{}
return &DummyPost{}, map[string]interface{}{}
}

switch spec.PostRun.Function {
case PostRunFunctionRedis:
return redis.GetPost(config)
return redis.GetPost(config), spec.PostRun.Args
}
return &DummyPost{}
return &DummyPost{}, map[string]interface{}{}
}

0 comments on commit ca34e81

Please sign in to comment.