Skip to content

Commit 4209598

Browse files
committedMay 28, 2014
Fix Config.Set() error handling
Fixes nsqio#37
1 parent 2cdc7dc commit 4209598

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed
 

‎config.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -183,27 +183,28 @@ func (c *Config) Set(option string, value interface{}) error {
183183
dest := unsafeValueOf(fieldVal)
184184
coercedVal, err := coerce(value, field.Type)
185185
if err != nil {
186-
log.Fatalf("ERROR: failed to coerce option %s (%v) - %s",
186+
return fmt.Errorf("failed to coerce option %s (%v) - %s",
187187
option, value, err)
188188
}
189189
if min != "" {
190190
coercedMinVal, _ := coerce(min, field.Type)
191191
if valueCompare(coercedVal, coercedMinVal) == -1 {
192-
return errors.New(fmt.Sprintf("invalid %s ! %v < %v",
193-
option, coercedVal.Interface(), coercedMinVal.Interface()))
192+
return fmt.Errorf("invalid %s ! %v < %v",
193+
option, coercedVal.Interface(), coercedMinVal.Interface())
194194
}
195195
}
196196
if max != "" {
197197
coercedMaxVal, _ := coerce(max, field.Type)
198198
if valueCompare(coercedVal, coercedMaxVal) == 1 {
199-
return errors.New(fmt.Sprintf("invalid %s ! %v > %v",
200-
option, coercedVal.Interface(), coercedMaxVal.Interface()))
199+
return fmt.Errorf("invalid %s ! %v > %v",
200+
option, coercedVal.Interface(), coercedMaxVal.Interface())
201201
}
202202
}
203203
dest.Set(coercedVal)
204+
return nil
204205
}
205206

206-
return errors.New(fmt.Sprintf("ERROR: invalid option %s", option))
207+
return fmt.Errorf("invalid option %s", option)
207208
}
208209

209210
// because Config contains private structs we can't use reflect.Value

0 commit comments

Comments
 (0)
Please sign in to comment.