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

html/template: parse failures lack sufficient context for debugging #20773

Open
michaelsafyan opened this issue Jun 23, 2017 · 8 comments
Open
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@michaelsafyan
Copy link

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

Unsure; this is in the Blaze version of "go_binary", "go_library", etc. (I'm having difficulty understanding which particular version of Go that is invoking).

What operating system and processor architecture are you using (go env)?

gLinux (Ubuntu 14.04.5 LTS) and also BuildRabbit

What did you do?

import (
   // ...
  "html/template",
   // ...
)

// ...
func CreateTemplate(name, text string) (*template.Template, error) {
    var newTemplate *template.Template
    newTemplate = template.New(name).Funcs(funcMap)
    parsedTemplate, err := newTemplate.Parse(text)
    if error != nil {
                return nil, status.Errorf(
			status.InvalidArgument,
			"error parsing template: %v")
    }
    return newTemplate, nil
}
// ...

What did you expect to see?

When the parsing fails, I expect the error to include sufficient context to diagnose. For example:

error parsing template: template: body:3 unexpected bad character U+002D '-' in command in the vicinity of "{{end-}}"; expected " " or "}}".

What did you see instead?

The error does not give any context. For example, it prints:

 error parsing template: template: body:3 unexpected bad character U+002D '-' in command

Or:

  error parsing template: template: body:14 unexpected bad character U+002D '-' in template clause

... but doesn't give any surrounding context to understand what the specific error is.

@odeke-em odeke-em changed the title Parser failures in "html/template" package lack sufficient context for debugging. html/template: parse failures lack sufficient context for debugging Jun 23, 2017
@odeke-em
Copy link
Member

I'll triage this for Go1.10, but if someone thinks this should be for Unplanned, please feel free and change that.

@odeke-em odeke-em added this to the Go1.10 milestone Jun 23, 2017
@ianlancetaylor
Copy link
Contributor

This may be a partial dup of #19408, which is about column information.

Other than that I think we need specific examples to improve. Show us a bad template, and the error you get, and how the error could be better. Thanks.

@ianlancetaylor ianlancetaylor modified the milestones: Go1.10, Unplanned Dec 8, 2017
@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 8, 2017
@michaelsafyan
Copy link
Author

What's the best way to share such examples? Is there an @google.com email alias that I can share with privately?

@skimbrel
Copy link

skimbrel commented Jul 5, 2018

Any idea when this might be addressed? Just ran smack into it when trying to make changes to a golang project:

EROR[20:32:00.378-07:00] Server error code=500 method=GET path=/groups err="html/template:groups: ends in a non-text context: {stateRCDATA delimNone urlPartNone jsCtxRegexp attrNone elementTextarea <nil>}"

There's no line number in this error message and I have no idea aside from just commenting out vast swaths of template how to start finding the problem.

@zaddok
Copy link

zaddok commented Jan 5, 2019

Im using Go 1.11, I have just hit this error as well. It is not clear to me where in the template might be the problem.

@empijei
Copy link
Contributor

empijei commented Apr 16, 2019

@skimbrel I opened #30635 to track your specific error, which is not what this bug is about. The issue with your problem is that the provided template ends unexpectedly. That error is saying "unexpected EOF while parsing".

About this bug: how would you thing should errors be reported?

@zaddok could you please post here your errors and what you'd like to have instead?

@xiazemin
Copy link

Any idea when this might be addressed? Just ran smack into it when trying to make changes to a golang project:

EROR[20:32:00.378-07:00] Server error code=500 method=GET path=/groups err="html/template:groups: ends in a non-text context: {stateRCDATA delimNone urlPartNone jsCtxRegexp attrNone elementTextarea <nil>}"

There's no line number in this error message and I have no idea aside from just commenting out vast swaths of template how to start finding the problem.

replace <textarea id="story" name="story" rows="5" cols="33">
with

<textarea id="story" name="story" rows="5" cols="33"></textarea>

it works fine

@EleisonC
Copy link

Any idea when this might be addressed? Just ran smack into it when trying to make changes to a golang project:
EROR[20:32:00.378-07:00] Server error code=500 method=GET path=/groups err="html/template:groups: ends in a non-text context: {stateRCDATA delimNone urlPartNone jsCtxRegexp attrNone elementTextarea <nil>}"
There's no line number in this error message and I have no idea aside from just commenting out vast swaths of template how to start finding the problem.

replace <textarea id="story" name="story" rows="5" cols="33"> with <textarea id="story" name="story" rows="5" cols="33"></textarea> it works fine

literally close it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

8 participants