Skip to content

Print out more info #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (i *injector) Get(t reflect.Type) reflect.Value {
}
}
if len(impls) > 1 && i.options.PanicOnAmbiguity {
panic(fmt.Sprintf("Expect single matching implementation but found %v", len(impls)))
panic(fmt.Sprintf("Expected single matching implementation for type <%v> but found %v: %v", t, len(impls), impls))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does reflect.Value stringify nicely for all types? The documentation for reflect.Value's String() method (https://golang.org/pkg/reflect/#Value.String) says "The fmt package treats Values specially. It does not call their String method implicitly but instead prints the concrete values they hold.", but your test seems to indicate it prints the type, so I don't know what to believe anymore.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm not sure why fmt package is not doing what it says, but from what I see, Value is printed as where T is v's type. So that suggests fmt package is calling String() method?

}
if len(impls) > 0 {
val = impls[0]
Expand Down
2 changes: 1 addition & 1 deletion inject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestInjectImplementors_AmbiguousImplementation(t *testing.T) {
func TestInjectImplementors_AmbiguousImplementationPanic(t *testing.T) {
defer func() {
r := recover()
expect(t, r, "Expect single matching implementation but found 2")
expect(t, r, "Expected single matching implementation for type <fmt.Stringer> but found 2: [<*inject.Greeter Value> <*inject.Greeter2 Value>]")
}()

injector := New()
Expand Down