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

Looks like godot is making a mess with file handling #32

Open
VictorAssunc opened this issue Aug 28, 2023 · 3 comments
Open

Looks like godot is making a mess with file handling #32

VictorAssunc opened this issue Aug 28, 2023 · 3 comments

Comments

@VictorAssunc
Copy link

VictorAssunc commented Aug 28, 2023

Context

I'm using https://github.com/valyala/quicktemplate to generate pages. quicktemplate generate code following the .qtpl file. So, if I have a template named foo.qtpl it generates a foo.qtpl.go.

The problem

I have a 943-line foo.qtpl file that generates an 822-line foo.qtpl.go file. When I run godot for the foo.qtpl.go file, it fails with the following message: Failed to run linter on file '/path/to/foo.qtpl.go': parse input file: inconsistency between file and AST: /path/to/foo.qtpl.
Pay attention to the file paths on the message.

Debugging a little, I found where the error occurs:

godot/getters.go

Lines 63 to 65 in a43fe64

if p := pf.fset.Position(lastComment.End()); len(pf.lines) < p.Line {
return nil, fmt.Errorf("inconsistency between file and AST: %s", p.Filename)
}

When printing fmt.Println(len(pf.lines), p.Line) I got the following results: 822 943. Note that 822 is the number of lines that foo.qtpl.go has and that 943 is the number of lines in foo.qtpl. I didn't debug anymore, so I'm not sure if it's a godot or golang bug.

I can investigate further if I have time, but I don't promise.

Edit: I'm using the last godot version

@VictorAssunc VictorAssunc changed the title Looks like godot is making a mess with file handling. Looks like godot is making a mess with file handling Aug 28, 2023
@tetafro
Copy link
Owner

tetafro commented Sep 17, 2023

Yep, interesting. This is a kind of error that "should never happen" :)
My only guess without looking at the code, that quicktemplate produces code which is not formatted. And this somehow affects godot. You can check it by running gofmt -d /path/to/foo.qtpl.go.

But of course it'd be easier if you just shared a reproducable example so I could debug it myself.

@igorscandido
Copy link

igorscandido commented Oct 10, 2023

Yep, interesting. This is a kind of error that "should never happen" :) My only guess without looking at the code, that quicktemplate produces code which is not formatted. And this is somehow affects godot. You can check it by running gofmt -d /path/to/foo.qtpl.go.

But of course it'd be easier if you just shared a reproducable example so I could debug it myself.

Hello @tetafro, I'm facing the same problem and I generated some code to try to help you debug it: https://github.com/igorscandido/GodotIssue-32

You can run make godot on branch error and you will see the same problem as @VictorAssunc described above.

It seems that the problem is that .qtpl file is bigger than .qtpl.go file, which causes it to fail.

For you to be able to teste both cases I separated a code that works (.qtpl size is smaller than .qtpl.go) in branch success and another that fails (with the problem me and @VictorAssunc described above) on the branch error.

@tetafro
Copy link
Owner

tetafro commented Nov 10, 2023

Thanks for the detailed report, it helped a lot.
TIL about the line compiler directive (docs), which affects parsed code and sets filenames. It was the source of the problem.

I fixed this in v1.4.16 (this commit).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants