-
Notifications
You must be signed in to change notification settings - Fork 48
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
Try/catch for 4.x #299
Try/catch for 4.x #299
Conversation
Benchmark results in web4 https://nda.ya.ru/3RiZii |
@@ -947,7 +947,7 @@ describe('BEMHTML compiler/Runtime', function() { | |||
}); | |||
}); | |||
|
|||
it('should throw error with one apply', function() { | |||
xit('should throw error with one apply', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only question is: what shall I do with this cases? I think, as long as we introduce try/catch for block rendering it not valid anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since it depend on this.options.debug
there is should be two ways of tests: with throwing and without
JSON.stringify(context.elemMods) | ||
].join(' ') + | ||
'\n' + | ||
e + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.stack
?
630c9e4
to
f1637a3
Compare
Updated. |
@@ -375,7 +375,8 @@ BEMHTML.prototype.runOne = function runOne(json) { | |||
ent.init(block, elem); | |||
} | |||
|
|||
var res = ent.run(context); | |||
var res = this.tryRun(context, ent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FOR Minor: if debug !== true ent.run
FOR Maj: this.tryRun
f1637a3
to
93963b7
Compare
I introduced $ cat stand.js
var bem = require('./');
var template = bem.compile(function() {
block('page').attrs()(function() {
var undef = applyNext();
return undef.test = 'foo';
});
}, { production: true });
var html = template.apply({ block: 'wrap', content: { block: 'page' } });
console.log(html);
$ node stand.js
BEMXJST ERROR: cannot render block page, elem undefined, mods {}, elemMods {} [TypeError: Cannot set property 'test' of undefined]
<div class="wrap"></div> This way allows us to maintain backward capability. Also developers do not miss errors, since by default the program will stop its work. We can release it as minor. |
Notice that there is no documentation in v4.x when I port this feature to v5 and higher I also add documentation. |
var res; | ||
|
||
try { | ||
res = ent.run(context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can return
right here without unnecessary res
variable
LGTM, except one comment |
try { | ||
res = ent.run(context); | ||
} catch (e) { | ||
console.error('BEMXJST ERROR: cannot render ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't it be more informative to show whole context:
console.error('BEMXJST ERROR: cannot render ' + JSON.stringify(context, null, 4), e);
also it's possible to get rid of res
:
try {
return ent.run(context);
} catch (e) {
console.error(/* ... */);
}
return '';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tadatuta context contains circular structure and many information useless for debugging in this case.
93963b7
to
11dfe87
Compare
'elem ' + context.elem, | ||
'mods ' + JSON.stringify(context.mods), | ||
'elemMods ' + JSON.stringify(context.elemMods) | ||
].join(', '), e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.stack || e
, please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@St-Lukas e.stack is useless:
93:trycatch miripiruni$ node stand.js
BEMXJST ERROR: cannot render block page, elem undefined, mods {}, elemMods {} TypeError: Cannot set property 'test' of undefined
at ContextChild. (evalmachine.:1863:19)
at Match.tryCatch (evalmachine.:1240:15)
at Match.exec (evalmachine.:1290:16)
at Entity.defaultBody (evalmachine.:266:26)
at Entity.run (evalmachine.:251:15)
at BEMHTML.tryRun (evalmachine.:681:16)
at BEMHTML.runOne (evalmachine.:663:10)
at BEMHTML._run (evalmachine.:531:16)
at BEMHTML.renderContent (evalmachine.:970:18)
at BEMHTML.renderClose (evalmachine.:831:19)
JFYI: Pulse test results: https://nda.ya.ru/3RiZii |
I think we can merge it. And port to 5.x, 6.x, 7.x. |
41e3be4
to
11dfe87
Compare
yes |
Also in v5.2.0 |
Also in v6.7.0 |
Also in v7.4.0 |
See #298
Original task: https://nda.ya.ru/3RiZp2