mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-20 15:00:42 -07:00
fix nested render error message
This commit is contained in:
@@ -31,6 +31,10 @@ ParseError.prototype = Object.create(Error.prototype);
|
|||||||
ParseError.prototype.constructor = ParseError;
|
ParseError.prototype.constructor = ParseError;
|
||||||
|
|
||||||
function RenderError(e, tpl) {
|
function RenderError(e, tpl) {
|
||||||
|
// return the original render error
|
||||||
|
if(e instanceof RenderError){
|
||||||
|
return e;
|
||||||
|
}
|
||||||
this.name = this.constructor.name;
|
this.name = this.constructor.name;
|
||||||
this.stack = e.stack;
|
this.stack = e.stack;
|
||||||
|
|
||||||
|
|||||||
+33
-3
@@ -10,6 +10,9 @@ var strictEngine = require('../..')({
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('error', function() {
|
describe('error', function() {
|
||||||
|
afterEach(function(){
|
||||||
|
mock.restore();
|
||||||
|
});
|
||||||
|
|
||||||
describe('TokenizationError', function() {
|
describe('TokenizationError', function() {
|
||||||
it('should throw TokenizationError when tag illegal', function() {
|
it('should throw TokenizationError when tag illegal', function() {
|
||||||
@@ -78,7 +81,9 @@ describe('error', function() {
|
|||||||
|
|
||||||
describe('RenderError', function() {
|
describe('RenderError', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
engine = require('../..')();
|
engine = require('../..')({
|
||||||
|
root: '/'
|
||||||
|
});
|
||||||
engine.registerTag('throwingTag', {
|
engine.registerTag('throwingTag', {
|
||||||
render: function() {
|
render: function() {
|
||||||
throw new Error('intended render error');
|
throw new Error('intended render error');
|
||||||
@@ -131,7 +136,7 @@ describe('error', function() {
|
|||||||
expect(e.message).to.contain('undefined variable: a');
|
expect(e.message).to.contain('undefined variable: a');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should contain template content in err.message', function() {
|
it('should contain template context in err.stack', function() {
|
||||||
var html = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th'];
|
var html = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th'];
|
||||||
var message = [
|
var message = [
|
||||||
' 2| 2nd',
|
' 2| 2nd',
|
||||||
@@ -150,6 +155,31 @@ describe('error', function() {
|
|||||||
expect(err.name).to.equal('RenderError');
|
expect(err.name).to.equal('RenderError');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it.only('should contain original template context in err.stack', function() {
|
||||||
|
var origin = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th'];
|
||||||
|
mock({
|
||||||
|
'/throwing-tag.html': origin.join('\n')
|
||||||
|
});
|
||||||
|
var html = '{%include "throwing-tag.html"%}';
|
||||||
|
var message = [
|
||||||
|
' 2| 2nd',
|
||||||
|
' 3| 3rd',
|
||||||
|
'>> 4| X{%throwingTag%} Y',
|
||||||
|
' 5| 5th',
|
||||||
|
' 6| 6th',
|
||||||
|
' 7| 7th',
|
||||||
|
'Error: intended render error',
|
||||||
|
];
|
||||||
|
return expect(engine.parseAndRender(html)).to.eventually
|
||||||
|
.be.rejected
|
||||||
|
.then(function(err) {
|
||||||
|
console.log(err.message);
|
||||||
|
console.log(err.stack);
|
||||||
|
expect(err.message).to.equal('intended render error, line:4');
|
||||||
|
expect(err.stack).to.contain(message.join('\n'));
|
||||||
|
expect(err.name).to.equal('RenderError');
|
||||||
|
});
|
||||||
|
});
|
||||||
it('should contain the whole template content in err.input', function() {
|
it('should contain the whole template content in err.input', function() {
|
||||||
var html = 'bar\nfoo{%throwingTag%}\nfoo';
|
var html = 'bar\nfoo{%throwingTag%}\nfoo';
|
||||||
return expect(engine.parseAndRender(html)).to.eventually
|
return expect(engine.parseAndRender(html)).to.eventually
|
||||||
@@ -245,7 +275,7 @@ describe('error', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should contain template content in err.message', function() {
|
it('should contain template context in err.stack', function() {
|
||||||
var html = ['1st', '2nd', '3rd', 'X{% a %} {% enda %} Y', '5th', '6th', '7th'];
|
var html = ['1st', '2nd', '3rd', 'X{% a %} {% enda %} Y', '5th', '6th', '7th'];
|
||||||
var message = [
|
var message = [
|
||||||
' 2| 2nd',
|
' 2| 2nd',
|
||||||
|
|||||||
Reference in New Issue
Block a user