wire: improve error message for provider set conflicts (google/go-cloud#500)

This commit is contained in:
Robert van Gent
2018-10-04 14:19:25 -07:00
committed by Ross Light
parent be8ecba636
commit b1fd26c92a
6 changed files with 160 additions and 27 deletions

View File

@@ -0,0 +1,45 @@
// Copyright 2018 The Go Cloud Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"io"
"strings"
"github.com/google/go-cloud/wire"
)
type context struct{}
func main() {}
type Foo string
type Bar io.Reader
var Set = wire.NewSet(provideFoo)
var SuperSet = wire.NewSet(Set)
var SetWithDuplicateBindings = wire.NewSet(Set, SuperSet)
func provideFoo() Foo {
return Foo("foo")
}
func provideFooAgain() Foo {
return Foo("foo foo")
}
func provideBar() Bar {
return io.Reader(strings.NewReader("hello"))
}

View File

@@ -0,0 +1,53 @@
// Copyright 2018 The Go Cloud Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//+build wireinject
package main
import (
"strings"
"github.com/google/go-cloud/wire"
)
func inject() Foo {
// fail: provideFoo and provideFooAgain both provide Foo.
panic(wire.Build(provideFoo, provideFooAgain))
}
func injectFromSet() Foo {
// fail: provideFoo is also provided by Set.
panic(wire.Build(provideFoo, Set))
}
func injectFromNestedSet() Foo {
// fail: provideFoo is also provided by SuperSet, via Set.
panic(wire.Build(provideFoo, SuperSet))
}
func injectFromSetWithDuplicateBindings() Foo {
// fail: DuplicateBindingsSet has two providers for Foo.
panic(wire.Build(SetWithDuplicateBindings))
}
func injectDuplicateValues() Foo {
// fail: provideFoo and wire.Value both provide Foo.
panic(wire.Build(provideFoo, wire.Value(Foo("foo"))))
}
func injectDuplicateInterface() Bar {
// fail: provideBar and wire.Bind both provide Bar.
panic(wire.Build(provideBar, wire.Bind(new(Bar), strings.NewReader("hello"))))
}

View File

@@ -0,0 +1 @@
example.com/foo

View File

@@ -0,0 +1,6 @@
/wire_gopath/src/example.com/foo/wire.go:27:8: wire.Build has multiple bindings for example.com/foo.Foo (current binding: provider "provideFooAgain" (/wire_gopath/src/example.com/foo/foo.go:39:6); previous binding: provider "provideFoo" (/wire_gopath/src/example.com/foo/foo.go:35:6)
/wire_gopath/src/example.com/foo/wire.go:32:8: wire.Build has multiple bindings for example.com/foo.Foo (current binding: provider "provideFoo" (/wire_gopath/src/example.com/foo/foo.go:35:6); previous binding: provider "provideFoo" (/wire_gopath/src/example.com/foo/foo.go:35:6) <- provider set "Set" (/wire_gopath/src/example.com/foo/foo.go:31:11)
/wire_gopath/src/example.com/foo/wire.go:37:8: wire.Build has multiple bindings for example.com/foo.Foo (current binding: provider "provideFoo" (/wire_gopath/src/example.com/foo/foo.go:35:6); previous binding: provider "provideFoo" (/wire_gopath/src/example.com/foo/foo.go:35:6) <- provider set "Set" (/wire_gopath/src/example.com/foo/foo.go:31:11) <- provider set "SuperSet" (/wire_gopath/src/example.com/foo/foo.go:32:16)
/wire_gopath/src/example.com/foo/foo.go:33:32: SetWithDuplicateBindings has multiple bindings for example.com/foo.Foo (current binding: provider "provideFoo" (/wire_gopath/src/example.com/foo/foo.go:35:6) <- provider set "Set" (/wire_gopath/src/example.com/foo/foo.go:31:11) <- provider set "SuperSet" (/wire_gopath/src/example.com/foo/foo.go:32:16); previous binding: provider "provideFoo" (/wire_gopath/src/example.com/foo/foo.go:35:6) <- provider set "Set" (/wire_gopath/src/example.com/foo/foo.go:31:11)
/wire_gopath/src/example.com/foo/wire.go:47:8: wire.Build has multiple bindings for example.com/foo.Foo (current binding: wire.Value (/wire_gopath/src/example.com/foo/wire.go:47:42); previous binding: provider "provideFoo" (/wire_gopath/src/example.com/foo/foo.go:35:6)
/wire_gopath/src/example.com/foo/wire.go:52:8: wire.Build has multiple bindings for example.com/foo.Bar (current binding: wire.Bind (/wire_gopath/src/example.com/foo/wire.go:52:31); previous binding: provider "provideBar" (/wire_gopath/src/example.com/foo/foo.go:43:6)