Exec executes the command chain. The first errored function terminates the chain and the error is returned. Otherwise, returns nil.
()
| 108 | // The first errored function terminates the chain and the |
| 109 | // error is returned. Otherwise, returns nil. |
| 110 | func (a *ActiveCommandChain) Exec() error { |
| 111 | a.executing = true |
| 112 | defer func() { a.executing = false }() |
| 113 | |
| 114 | for _, f := range a.funcs { |
| 115 | if f.f == nil { |
| 116 | if f.s != "" { |
| 117 | a.log.Println(f.s, "...") |
| 118 | a.lastStage = f.s |
| 119 | } |
| 120 | continue |
| 121 | } |
| 122 | |
| 123 | // success |
| 124 | err := f.f() |
| 125 | if err == nil { |
| 126 | continue |
| 127 | } |
| 128 | |
| 129 | // warning |
| 130 | if _, ok := err.(errNonFatal); ok { |
| 131 | if a.lastStage == "" { |
| 132 | a.log.Warnln(err) |
| 133 | } else { |
| 134 | a.log.Warnln(fmt.Errorf("error at '%s': %w", a.lastStage, err)) |
| 135 | } |
| 136 | continue |
| 137 | } |
| 138 | |
| 139 | // error |
| 140 | if a.lastStage == "" { |
| 141 | return err |
| 142 | } |
| 143 | return fmt.Errorf("error at '%s': %w", a.lastStage, err) |
| 144 | } |
| 145 | return nil |
| 146 | } |
| 147 | |
| 148 | // Retry retries `f` up to `count` times at interval. |
| 149 | // If after `count` attempts there is an error, the command chain is terminated with the final error. |
no outgoing calls
no test coverage detected