@@ -79,7 +79,7 @@ func (l *loader) register(key string, entry Entry) {
79
79
category , entryKey , exists := walk (l .defaults , key )
80
80
if exists {
81
81
if ! reflect .DeepEqual (& entry , category [entryKey ].(* Entry )) {
82
- panic (errors .New ( fmt . Errorf ("attempted to override registered config entry %q" , key ) ))
82
+ panic (errors .Errorf ("attempted to override registered config entry %q" , key ))
83
83
}
84
84
} else {
85
85
category [entryKey ] = & entry
@@ -188,10 +188,8 @@ func (l *loader) readConfigFile(filesystem fs.FS, file string) (o object, err er
188
188
}
189
189
}()
190
190
jsonParser := json .NewDecoder (configFile )
191
- err = jsonParser .Decode (& o )
192
- }
193
-
194
- if err != nil {
191
+ err = errors .New (jsonParser .Decode (& o ))
192
+ } else {
195
193
err = errors .New (err )
196
194
}
197
195
@@ -243,7 +241,7 @@ func walk(currentCategory object, key string) (object, string, bool) {
243
241
currentCategory = category
244
242
} else {
245
243
if dotIndex < len (key ) {
246
- panic (errors .New ( fmt . Errorf ("attempted to add an entry to non-category %q" , key [:dotIndex ]) ))
244
+ panic (errors .Errorf ("attempted to add an entry to non-category %q" , key [:dotIndex ]))
247
245
}
248
246
249
247
// Entry exists
@@ -263,7 +261,7 @@ func walk(currentCategory object, key string) (object, string, bool) {
263
261
}
264
262
}
265
263
266
- panic (errors .New ( fmt . Errorf ("attempted to replace the %q category with an entry" , key ) ))
264
+ panic (errors .Errorf ("attempted to replace the %q category with an entry" , key ))
267
265
}
268
266
269
267
// createMissingCategories based on the key path, starting at the given index.
@@ -355,7 +353,7 @@ func (c *Config) Get(key string) any {
355
353
return val
356
354
}
357
355
358
- panic (errors .New ( fmt . Errorf ("config entry \" %s\" doesn't exist" , key ) ))
356
+ panic (errors .Errorf ("config entry \" %s\" doesn't exist" , key ))
359
357
}
360
358
361
359
func (c * Config ) get (key string ) (any , bool ) {
@@ -396,7 +394,7 @@ func (c *Config) get(key string) (any, bool) {
396
394
func (c * Config ) GetString (key string ) string {
397
395
str , ok := c .Get (key ).(string )
398
396
if ! ok {
399
- panic (errors .New ( fmt . Errorf ("config entry \" %s\" is not a string" , key ) ))
397
+ panic (errors .Errorf ("config entry \" %s\" is not a string" , key ))
400
398
}
401
399
return str
402
400
}
@@ -406,7 +404,7 @@ func (c *Config) GetString(key string) string {
406
404
func (c * Config ) GetBool (key string ) bool {
407
405
val , ok := c .Get (key ).(bool )
408
406
if ! ok {
409
- panic (errors .New ( fmt . Errorf ("config entry \" %s\" is not a bool" , key ) ))
407
+ panic (errors .Errorf ("config entry \" %s\" is not a bool" , key ))
410
408
}
411
409
return val
412
410
}
@@ -416,7 +414,7 @@ func (c *Config) GetBool(key string) bool {
416
414
func (c * Config ) GetInt (key string ) int {
417
415
val , ok := c .Get (key ).(int )
418
416
if ! ok {
419
- panic (errors .New ( fmt . Errorf ("config entry \" %s\" is not an int" , key ) ))
417
+ panic (errors .Errorf ("config entry \" %s\" is not an int" , key ))
420
418
}
421
419
return val
422
420
}
@@ -426,7 +424,7 @@ func (c *Config) GetInt(key string) int {
426
424
func (c * Config ) GetFloat (key string ) float64 {
427
425
val , ok := c .Get (key ).(float64 )
428
426
if ! ok {
429
- panic (errors .New ( fmt . Errorf ("config entry \" %s\" is not a float64" , key ) ))
427
+ panic (errors .Errorf ("config entry \" %s\" is not a float64" , key ))
430
428
}
431
429
return val
432
430
}
@@ -436,7 +434,7 @@ func (c *Config) GetFloat(key string) float64 {
436
434
func (c * Config ) GetStringSlice (key string ) []string {
437
435
str , ok := c .Get (key ).([]string )
438
436
if ! ok {
439
- panic (errors .New ( fmt . Errorf ("config entry \" %s\" is not a string slice" , key ) ))
437
+ panic (errors .Errorf ("config entry \" %s\" is not a string slice" , key ))
440
438
}
441
439
return str
442
440
}
@@ -446,7 +444,7 @@ func (c *Config) GetStringSlice(key string) []string {
446
444
func (c * Config ) GetBoolSlice (key string ) []bool {
447
445
str , ok := c .Get (key ).([]bool )
448
446
if ! ok {
449
- panic (errors .New ( fmt . Errorf ("config entry \" %s\" is not a bool slice" , key ) ))
447
+ panic (errors .Errorf ("config entry \" %s\" is not a bool slice" , key ))
450
448
}
451
449
return str
452
450
}
@@ -456,7 +454,7 @@ func (c *Config) GetBoolSlice(key string) []bool {
456
454
func (c * Config ) GetIntSlice (key string ) []int {
457
455
str , ok := c .Get (key ).([]int )
458
456
if ! ok {
459
- panic (errors .New ( fmt . Errorf ("config entry \" %s\" is not an int slice" , key ) ))
457
+ panic (errors .Errorf ("config entry \" %s\" is not an int slice" , key ))
460
458
}
461
459
return str
462
460
}
@@ -466,7 +464,7 @@ func (c *Config) GetIntSlice(key string) []int {
466
464
func (c * Config ) GetFloatSlice (key string ) []float64 {
467
465
str , ok := c .Get (key ).([]float64 )
468
466
if ! ok {
469
- panic (errors .New ( fmt . Errorf ("config entry \" %s\" is not a float64 slice" , key ) ))
467
+ panic (errors .Errorf ("config entry \" %s\" is not a float64 slice" , key ))
470
468
}
471
469
return str
472
470
}
0 commit comments