Skip to content
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

Errors in go portions of a template report line numbers in the go file instead of the templ file #726

Open
Robert-Kolmos opened this issue May 4, 2024 · 2 comments
Labels
cmd enhancement New feature or request NeedsFix Needs implementing

Comments

@Robert-Kolmos
Copy link
Contributor

Hey all,

I've got a very simple templ file

package main

// : after parameter name is intentional
templ Template(invalid: string) {
	<div/>
}

When I run templ generate I get an error like the following

(✗) Error generating code [ file=/home/rkolmos/projects/templ-error-location-repro/main.templ error=/home/rkolmos/projects/templ-error-location-repro/main.templ source formatting error: 14:22: missing ',' in parameter list ]
(✗) Event handler failed [ error=failed to generate code for "/home/rkolmos/projects/templ-error-location-repro/main.templ": /home/rkolmos/projects/templ-error-location-repro/main.templ source formatting error: 14:22: missing ',' in parameter list ]
(✗) Error [ error=failed to generate code for "/home/rkolmos/projects/templ-error-location-repro/main.templ": /home/rkolmos/projects/templ-error-location-repro/main.templ source formatting error: 14:22: missing ',' in parameter list ]
(✗) Command failed: generation completed with 1 errors

To me it looks like what is happening is that the reported location is the location in the generated go file. It would be helpful if templ mapped that error back to it's location in the templ file similar to what the LSP does. The error is especially confusing if it is the first time the go file has been generated because there is nothing to reference to see what the offending line of code is.

Would the project be open to either?

  1. Mapping errors back to their location in the templ file.
  2. Providing a way to make templ generate keep invalid generated go files

If either of these is valuable I'd be happy to submit a PR.

@joerdav
Copy link
Collaborator

joerdav commented May 7, 2024

I think that mapping the errors would be most useful. We do store map ranges of go code to templ code so it should be possible.

@Robert-Kolmos
Copy link
Contributor Author

I'm hoping to have some time to do this this week. If that changes I'll update here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmd enhancement New feature or request NeedsFix Needs implementing
Projects
None yet
Development

No branches or pull requests

2 participants