Skip to content

Commit c69f466

Browse files
authored
Merge pull request #1708 from danhunsaker/fix/type-reporting
Fix `incorrectTypeForFlagError` for unknowns
2 parents 97e1edb + ef7074a commit c69f466

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

altsrc/map_input_source.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package altsrc
33
import (
44
"fmt"
55
"math"
6-
"reflect"
76
"strings"
87
"time"
98

@@ -471,11 +470,5 @@ func (fsm *MapInputSource) isSet(name string) bool {
471470
}
472471

473472
func incorrectTypeForFlagError(name, expectedTypeName string, value interface{}) error {
474-
valueType := reflect.TypeOf(value)
475-
valueTypeName := ""
476-
if valueType != nil {
477-
valueTypeName = valueType.Name()
478-
}
479-
480-
return fmt.Errorf("Mismatched type for flag '%s'. Expected '%s' but actual is '%s'", name, expectedTypeName, valueTypeName)
473+
return fmt.Errorf("Mismatched type for flag '%s'. Expected '%s' but actual is '%T'", name, expectedTypeName, value)
481474
}

altsrc/map_input_source_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package altsrc
22

33
import (
4+
"fmt"
45
"testing"
56
"time"
67
)
@@ -33,3 +34,8 @@ func TestMapInputSource_Int64Slice(t *testing.T) {
3334
expect(t, []int64{1, 2, 3}, d)
3435
expect(t, nil, err)
3536
}
37+
38+
func TestMapInputSource_IncorrectFlagTypeError(t *testing.T) {
39+
var testVal *bool
40+
expect(t, incorrectTypeForFlagError("test", "bool", testVal), fmt.Errorf("Mismatched type for flag 'test'. Expected 'bool' but actual is '*bool'"))
41+
}

0 commit comments

Comments
 (0)