Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
proposal: text/template: detect circular imports #21914
When working on a large template project that composed from a lot of files, and you accidentally created an import cycle, what you will get on the execution is a huge chunk that is hard to debug and figure out where was the problem.
I'm proposing to add support for circular import detection in the template package, and return an informative message in cases like this.
Also, if this proposal will be accepted, I would like to create a CL.
Here's an example that demonstrates that: https://play.golang.org/p/6moF8cH8rW
@a8m thank you for the proposal/request. This looks interesting, and IMHO fire away and go ahead with a prototype for it; the results will perhaps give more weight to your proposal. The complexity, invasiveness, benefits are easier to evaluate with an exhibit, so all yours ;)
Of course the due process proposal reviews will be performed.
This is no different from a program that calls itself recursively:
We don't detect those in the Go compiler because it's very difficult in general. I was going to suggest a maximum depth check, but there's already one in the code. If I change the snippet to use the error result and show it:
then I get:
That seems to be working correctly.