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

"unexpected {{end}}" error that only happens when using --input-dir #238

Closed
jcelliott opened this issue Dec 15, 2017 · 6 comments
Closed
Labels

Comments

@jcelliott
Copy link

Given the following template and datasource:

template.txt

{{with $config := datasource "config"}}
hello, {{$config.test }}
{{end}}

config.toml

test = "asdf"

Calling gomplate like this works as expected:

> gomplate -f templates/template.txt -d config=config.toml
hello, asdf

But calling it like this results in an error:

> gomplate --input-dir templates --output-dir out -d config=config.toml
Error: template: template:3: unexpected {{end}}

I've looked (quickly) through the code and can't see any reason why this would be happening, it looks like it's mostly the same code path.

@hairyhenderson
Copy link
Owner

Thanks for reporting this, @jcelliott!

This is a super weird bug, for sure.

I haven't been able to reproduce it yet:

$ gomplate -f templates/template.txt -d config=config.toml

hello, asdf

$ gomplate --input-dir templates --output-dir out -d config=config.toml
$ cat out/template.txt 

hello, asdf

I'll fiddle around and see if I can reproduce...

@hairyhenderson
Copy link
Owner

Nope, still haven't been able to reproduce at all. Can you confirm that templates/template.txt file you have looks exactly as you pasted? And, which version of gomplate are you using?

@jcelliott
Copy link
Author

Yeah, I just double checked. The template is exactly the same.

I tried latest gomplate with go get -u github.com/hairyhenderson/gomplate. I also checked out the latest tag (2.2.0) and rebuilt (with Go 1.9.2). And then I also downloaded a precompiled binary of the latest release. They all have the same behavior.

@jcelliott
Copy link
Author

jcelliott commented Dec 18, 2017

I just figured it out 😆 . It consistently failed while I had the template open in vim. When I closed it everything worked as expected. It was trying to template the .template.txt.swp file.

It looks like there's an --exclude option, but I wonder if it should ignore hidden files by default.

This also makes me think it would be nice to have the specific file where a failure occurred in the error message. That would have made it very obvious what the problem was.

Thanks for looking into this.

@hairyhenderson
Copy link
Owner

😆 Good find! Glad you solved this 🙂

I'm not so sure about excluding hidden files by default - the use-case of using gomplate to template config files (which can start with .s in some cases) would break.

However, I definitely agree that the error should have been more clear! I'll log an issue for that and see if I can work on it. I'm on vacation in Africa right now (which is why it's taken so long for me to respond!) but I have a semi-reliable internet connection and a computer with more-or-less the right dev tools, so I'll take a stab at it 😉

@hairyhenderson
Copy link
Owner

@jcelliott I've just merged #240 which puts the filename in the error message - should stop head-scratchers like this in the future 😉

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

No branches or pull requests

2 participants