mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/load: better error reporting for import cycles (#3266)
This commit is contained in:
@@ -210,6 +210,23 @@ import _ "<project>/ent/runtime"
|
||||
```
|
||||
:::
|
||||
|
||||
#### Import Cycle Error
|
||||
|
||||
At the first attempt to set up schema hooks in your project, you may encounter an error like the following:
|
||||
```text
|
||||
entc/load: parse schema dir: import cycle not allowed: [ent/schema ent/hook ent/ ent/schema]
|
||||
To resolve this issue, move the custom types used by the generated code to a separate package: "Type1", "Type2"
|
||||
```
|
||||
|
||||
The error may occur because the generated code relies on custom types defined in the `ent/schema` package, but this
|
||||
package also imports the `ent/hook` package. This indirect import of the `ent` package creates a loop, causing the error
|
||||
to occur. To resolve this issue, follow these instructions:
|
||||
|
||||
- First, comment out any usage of hooks, privacy policy, or interceptors from the `ent/schema`.
|
||||
- Move the custom types defined in the `ent/schema` to a new package, for example, `ent/schema/schematype`.
|
||||
- Run `go generate ./...` to update the generated `ent` package to point to the new package. For example, `schema.T` becomes `schematype.T`.
|
||||
- Uncomment the hooks, privacy policy, or interceptors, and run `go generate ./...` again. The code generation should now pass without error.
|
||||
|
||||
## Evaluation order
|
||||
|
||||
Hooks are called in the order they were registered to the client. Thus, `client.Use(f, g, h)`
|
||||
|
||||
Reference in New Issue
Block a user