Skip to content

Commit b5af749

Browse files
authored
Merge pull request #607 from mattbostock/prevent_panic
Prevent panic on failed config load
2 parents f2ba86e + 890f148 commit b5af749

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

api/api.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (api *API) Register(r *route.Router) {
127127
}
128128

129129
// Update sets the configuration string to a new value.
130-
func (api *API) Update(cfg string, resolveTimeout time.Duration) {
130+
func (api *API) Update(cfg string, resolveTimeout time.Duration) error {
131131
api.mtx.Lock()
132132
defer api.mtx.Unlock()
133133

@@ -137,8 +137,11 @@ func (api *API) Update(cfg string, resolveTimeout time.Duration) {
137137
configJSON, err := config.Load(cfg)
138138
if err != nil {
139139
log.Errorf("error: %v", err)
140+
return err
140141
}
142+
141143
api.configJSON = *configJSON
144+
return nil
142145
}
143146

144147
type errorType string

cmd/alertmanager/main.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ func main() {
208208
return err
209209
}
210210

211-
apiv.Update(conf.String(), time.Duration(conf.Global.ResolveTimeout))
211+
err = apiv.Update(conf.String(), time.Duration(conf.Global.ResolveTimeout))
212+
if err != nil {
213+
return err
214+
}
212215

213216
tmpl, err = template.FromGlobs(conf.Templates...)
214217
if err != nil {

0 commit comments

Comments
 (0)