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

Unhelpful error message: "Failed to compile template. caused by: Rust Syntax Error (unexpected token)" #53

Open
d4h0 opened this issue Feb 3, 2021 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@d4h0
Copy link

d4h0 commented Feb 3, 2021

Hi,

I just tried to find out, if custom filters can be defined:

<% "foo" | foo %>

(I forgot the "-" after the opening tag)

...which resulted in the following error:

error: Failed to compile template.
caused by: Rust Syntax Error (unexpected token)

file: /home/d4h0/projects/websites/ssg/templates/pages/test.stpl

  --> ssg/src/main.rs:33:10
   |
33 | #[derive(TemplateOnce)]
   |          ^^^^^^^^^^^^
   |
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

Would it be possible to provide more context, including the code that lead to the error?

I imagine, at the moment it would be quite difficult to debug syntax errors.

@d4h0
Copy link
Author

d4h0 commented Feb 3, 2021

Similarly (but more a nitpick in this case), the following error could have more/better details:

error[E0425]: cannot find value `content` in this scope
 --> /home/d4h0/projects/websites/ssg/target/debug/build/sailfish-compiler-d853660c680b883d/out/templates/article-69d5e134f14a8215:3:32
  |
3 |     __sf_rt::render!(__sf_buf, content);
  |                                ^^^^^^^ not found in this scope

Ideally, the error would contain the path of the template, the location of the error in the template, and the source line itself.

I have never created a procedural macro, so I don't know if it's possible to improve error messages.

PS: I hope it's okay, that I open so many issues. I'm pretty excited about sailfish, and I thought some feedback from new user would be useful to you. I have a few more questions, suggestions, and ideas, but if it is too much, just let me know... 🙃

Also, please don't feel any pressure to reply to my questions and suggestions quickly, or to implement anything. I just want to send you my feedback, as long as I still have a beginner's mind.

@d4h0
Copy link
Author

d4h0 commented Feb 3, 2021

I got an error that is like what I'd expect:

error: Failed to compile template.
caused by: Rust Syntax Error (expected `,`)

file: /home/dh/projects/websites/paypla/ssg/templates/pages/test.stpl
position: line 17, column 50

   |
17 | <| data2.replace(TestPageData {layout, title, vec![css]}) |>
   |                                                  ^

  --> ssg/src/main.rs:33:10
   |
33 | #[derive(TemplateOnce)]
   |          ^^^^^^^^^^^^
   |
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

(vec![css] should be css: vec![css])

So it seems, it's possible to get nice error messages. But maybe it depends on the kind of error.

@Kogia-sima
Copy link
Member

Kogia-sima commented Feb 3, 2021

I’m sorry for the late reply (I was just doing some experiments at lab).

The former error is a duplicate of #33. The progress of this issue is blocked due to 3rdparty library issue.

   |
3 | __sf_rt::render!(__sf_buf, content);
   |              ^^^^^^^ not found in this scope

Ideally, the error would contain the path of the template, the location of the error in the template, and the source line itself.

Currently sailfish heavily depends on syn crate for parsing Rust code. syn crate transforms the input sequence into AST, but it does not detect errors which requires semantic analysis. The solution is... to create a own Rust semantic analyzer from scratch. This is on my TODO list, but currently I have no time to do this.

@Kogia-sima
Copy link
Member

For now sailfish-compiler just transforms the input template into pure Rust code, write them into the temporary artifact (which is placed in target/debug/build/sailfish-compiler-***/out/templates/ directory), and then call std::include! for the artifact. That means sailfish-compiler intires workload on Rust compiler. We could just incorporate analyzer into sailfish compilation process to improve error messages.

@Kogia-sima Kogia-sima added the help wanted Extra attention is needed label Feb 3, 2021
Kogia-sima added a commit that referenced this issue Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants