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

Passing redundant attributes to a component fails the compilation with a cryptic error #253

Open
jakub-g opened this issue Jul 24, 2014 · 2 comments · May be fixed by #254
Open

Passing redundant attributes to a component fails the compilation with a cryptic error #253

jakub-g opened this issue Jul 24, 2014 · 2 comments · May be fixed by #254
Labels

Comments

@jakub-g
Copy link
Collaborator

jakub-g commented Jul 24, 2014

Let's consider the following plunk:

http://plnkr.co/edit/pPQWTgkzTLyBdBIX8vfQ?p=preview

MyItemCtrl.js

var klass = require("hsp/klass");

var MyItemCtrl= klass({
    attributes: {
        "foo" : { type : "string"},
        "bar" : { type : "string" }
    }
});

module.exports = MyItemCtrl;

hello.hsp

var MyItemCtrl = require("./MyItemCtrl");

{template Hello}
  <#myItem foo="FOO" bar="BAR" />
{/template}

{template myItem using ctrl:MyItemCtrl}
  foo = {ctrl.foo} <br>
  bar = {ctrl.bar} <br>
{/template}

module.exports = Hello;

So far so good, I define attributes in the controller (foo and bar) and pass them from Hello template to <#myItem> and everything works properly.

Now, let's change line 4 in hello.hsp from:

<#myItem foo="FOO" bar="BAR" /> 

to

<#myItem foo="FOO" bar="BAR" xxx="xxx" />

i.e. let's pass some redundant attrib that is not defined in attributes of the controller.

What we get is a compilation failure plus a cryptic error message:

TypeError: this.ctlAttributes[nm] is undefined
if (this.ctlAttributes[nm].type !== "template") {

I think the code should still compile fine, only raising a warning, with a better description of the issue.

@jakub-g jakub-g changed the title Passing redundant attributes to a component fails the compilations with a cryptic error Passing redundant attributes to a component fails the compilation with a cryptic error Jul 24, 2014
@jakub-g jakub-g added the bug label Jul 24, 2014
@PK1A
Copy link
Contributor

PK1A commented Jul 24, 2014

@jakub-g IMO it looks like a runtime error, rather than the compilation-time problem, no?

This obviously doesn't change the fact that a better error message is needed.

@PK1A
Copy link
Contributor

PK1A commented Jul 24, 2014

A smaller reduction of the same problem : http://plnkr.co/edit/x7GQBwZlPUz74mvCrqOi?p=preview
Basically whenever a non-defined custom attribute is passed to a componet markup we get this error.

A slight variation of the same situation is defining a controller like so:

var MyItemCtrl = klass({
});

In this case the error is:

Uncaught TypeError: Cannot read property 'foo' of undefined

We should fix both cases by failing with a clear error message.

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

Successfully merging a pull request may close this issue.

2 participants