wire
wire copied to clipboard
Due to the circular dependency, the wire cannot be generated, but the corresponding variable cannot be found when the error is reported.
Describe the bug
If I am in the following apps directory structure in app1 package, app.go
package app1
import (
"awesomeProject/wire_test/app"
"fmt"
)
type A struct {
C *app.C
}
func (a *A) Add(b app.B) {
fmt.Println(b)
}
in wire package , wire.go
//go:build wireinject
// +build wireinject
package wire
import (
"awesomeProject/wire_test/app"
"awesomeProject/wire_test/app/app1"
"github.com/google/wire"
)
func Inject() *app.B {
wire.Build(
wire.Struct(new(app1.A), "*"),
wire.Struct(new(app.B), "*"),
wire.Struct(new(app.C), "*"),
)
return nil
}
in intance.go
package app
import "awesomeProject/wire_test/app/app1"
type B struct {
A app1.A
}
type C struct {
}
As a result, the following error was reported. In fact, it should be a circular reference that caused the wire to fail to be generated
wire: /Users/genyuanguo/Desktop/awesomeProject/wire_test/app/wire/wire.go:13:1: inject Inject: no provider found for *invalid type
needed by awesomeProject/wire_test/app/app1.A in struct provider "A" (/Users/genyuanguo/Desktop/awesomeProject/wire_test/app/app1/app.go:8:6)
needed by *awesomeProject/wire_test/app.B in struct provider "B" (/Users/genyuanguo/Desktop/awesomeProject/wire_test/app/intance.go:5:6)
wire: awesomeProject/wire_test/app/wire: generate failed
wire: at least one generate failure
To Reproduce
. └── app |── app1 │ └── app.go |── intance.go └── wire |── wire.go └── wire_gen.go If you use the wire directory structure like this
Expected behavior
Should report an error app1 and app circular reference.
Version
github.com/google/wire v0.5.0
Additional context
Add any other context about the problem here.
I think I have a similar issue. I'm seeing wire flip flopping between success and failure - and giving a cryptic error message:
$ wire ./apps/agent
wire: apps/agent: wrote <...>/apps/agent/wire_gen.go
$ wire ./apps/agent
wire: <...>/apps/agent/t_serverbuild.go:36:26: cannot use a.Context() (value of type *engine.Context) as *invalid type value in argument to a.WebsocketWrite
I narrowed it down to a circular dependency that didn't actually occur when compiling the project the regular way (ie without the wireinject tag).
I solved this now by running go build -tags wireinject <directory with wire.go> first.