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

"Missing one or more blocks" not helpful enough #733

Closed
Tracked by #757
ysangkok opened this issue Jun 2, 2016 · 5 comments
Closed
Tracked by #757

"Missing one or more blocks" not helpful enough #733

ysangkok opened this issue Jun 2, 2016 · 5 comments
Milestone

Comments

@ysangkok
Copy link

ysangkok commented Jun 2, 2016

I have my log-level set to "DEBUG" but I still only get the error "Malformed template was missing one or more blocks.". It would be helpful if the block names were written when log-level=DEBUG.

@ysangkok ysangkok changed the title "Missing one or more blocks" "Missing one or more blocks" not helpful enough Jun 2, 2016
@sethkinast
Copy link
Contributor

Can you share your template or the piece that fails?

@sethkinast
Copy link
Contributor

The point of this error is that there aren't any blocks, because something is rather horribly wrong. But let's see what we can do to make the error more apparent after examining your template :)

@ysangkok
Copy link
Author

ysangkok commented Jun 6, 2016

@sethkinast here are the sources, I removed some HTML (shouldn't make a difference I guess).

base.dust:

<!doctype html>
<html>
  <head>
    <title>Company name</title>
    <style>
    .alert:empty {
      display: none;
    }
    </style>
  </head>
  <body>
    <div class="wrapper">
    <div id="content">
    <div class="container">

    <h1>{headline}</h1>
    <div class="alert alert-success">{+success/}</div>
    <div class="alert alert-info">{+info/}</div>
    <div class="alert alert-warning">{+warning/}</div>
    <div class="alert alert-danger">{+danger/}</div>

    {+content/}
    </div>
    </div>
    </div>

  </body>
</html>

activate.dust:

{>base/}

{<success}{?paramActivationSucceeded}
      <strong>
        {succeededHeadline}
      </strong>
      {succeededText}
{/paramActivationSucceeded}{/success}

{<danger}{?paramActivationFailed}
      {failedAlert}
{/paramActivationFailed}{/danger}

{<content}

  <div class=row>
    <div class=col-md-6>
      <form action="#">
        <p>{explanation}</p>
        <div class=form-group>
          <label for=token>{tokenInputFieldLabel}</label>
          <input id=token name=combinedToken class="form-control">
        </div>
        <div><input class="btn btn-default" type=submit value="{submitButton}"></div>
      </form>
    </div>
  </div>
{/content}

login.dust:

{>base/}

{<danger}{danger}{/danger}

{<headline}Login{/headline}

{<content}
                <form action='login?url={url|uc}' method="post">
                        <label for="userAlias">
                        userAlias:
                        </label>
                        <input name="userAlias" id="userAlias"/>

                        <br/>
                        <label for="password">password:</label>
                        <input name="password" id="password" />
                        <br/>
                        <input type="submit" />
                </form>
{/content}

@sethkinast sethkinast mentioned this issue Dec 6, 2016
5 tasks
@jimmyhchan jimmyhchan self-assigned this Dec 14, 2016
@jimmyhchan jimmyhchan added this to the 2.8 milestone Dec 14, 2016
@jimmyhchan
Copy link
Contributor

I believe the debug line for Malformed template here doesn't actually make sense. The template is not malformed.

Here is a reduced test case

const base = `<h1>{+pageHeader}LinkedIn{/pageHeader}</h1><div>{+bodyContent/}</div><div>{+pageFooter}default footer{/pageFooter}</div>`;
const good = `{>base/}{<pageHeader}new H1{/pageHeader}`;
const doesError = `{>base/}{+nono}no no no {/nono}`;
const shouldError = `{>base/}{<pageHeader}new H1 again{/pageHeader}{+nono}no no no {/nono}`;


var dust = require('./index');
dust.loadSource(dust.compile(base, 'base'));
dust.loadSource(dust.compile(good, 'good'));
dust.loadSource(dust.compile(doesError, 'doesErr'));
dust.loadSource(dust.compile(shouldError, 'shouldErr'));


dust.debugLevel='DEBUG';

['good', 'doesErr', 'shouldErr'].map(name=>{
  console.log(`rendering ${name}`);
  dust.render(name, {}, (e,o)=>{
    console.log(o);
  });
});

with more useful debugging

-    dust.log('Malformed template `' + this.getTemplateName() + '` was missing one or more blocks.');
-    return false;
+    dust.log('Malformed template `' + this.getTemplateName() + '` tried to find a block named `' + key + '` but it was not found.'); return false;

the above will output

rendering good
[DUST:INFO] Malformed template `base` tried to find a block named `bodyContent` but it was not found.
[DUST:INFO] Malformed template `base` tried to find a block named `pageFooter` but it was not found.
<h1>new H1</h1><div></div><div>default footer</div>
rendering doesErr
[DUST:DEBUG] No blocks for context `pageHeader` in template `base`
[DUST:DEBUG] No blocks for context `bodyContent` in template `base`
[DUST:DEBUG] No blocks for context `pageFooter` in template `base`
[DUST:DEBUG] No blocks for context `nono` in template `base`
<h1>LinkedIn</h1><div></div><div>default footer</div>no no no
rendering shouldErr
[DUST:INFO] Malformed template `base` tried to find a block named `bodyContent` but it was not found.
[DUST:INFO] Malformed template `base` tried to find a block named `pageFooter` but it was not found.
[DUST:INFO] Malformed template `base` tried to find a block named `nono` but it was not found.
<h1>new H1 again</h1><div></div><div>default footer</div>no no no

I propose we change the logic to use

dust.log('No blocks for context `' + key + '` in template `' + this.getTemplateName() + '`', DEBUG);

whenever blocks are not defined and whenever the key is not found in the list of known blocks

jimmyhchan added a commit to jimmyhchan/dustjs that referenced this issue Jan 10, 2017
jimmyhchan added a commit to jimmyhchan/dustjs that referenced this issue Jan 10, 2017
@ysangkok
Copy link
Author

Closing since I am no longer using Dustjs.

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