Skip to content

Commit 86f6bf0

Browse files
committed
fix: expose originalError from LiquidError, #742
1 parent 62bb20e commit 86f6bf0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/util/error.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const TRAIT = '__liquidClass__'
1010
export abstract class LiquidError extends Error {
1111
public token!: Token
1212
public context = ''
13-
private originalError?: Error
13+
public originalError?: Error
1414
public constructor (err: Error | string, token: Token) {
1515
/**
1616
* note: for ES5 targeting, `this` will be replaced by return value of Error(),

test/e2e/issues.spec.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TopLevelToken, TagToken, Tokenizer, Context, Liquid, Drop, toValueSync } from '../..'
1+
import { TopLevelToken, TagToken, Tokenizer, Context, Liquid, Drop, toValueSync, LiquidError } from '../..'
22
const LiquidUMD = require('../../dist/liquid.browser.umd.js').Liquid
33

44
describe('Issues', function () {
@@ -506,4 +506,13 @@ describe('Issues', function () {
506506
expect(liquid.parseAndRender('{{ 113 | uniq }}')).resolves.toEqual('113')
507507
expect(liquid.parseAndRender("{{ '113' | uniq }}")).resolves.toEqual('113')
508508
})
509+
it('Exposing originalError in LiquidError #742', () => {
510+
const engine = new Liquid()
511+
engine.registerFilter('error', () => { throw new Error('intended') })
512+
try {
513+
engine.parseAndRenderSync(`{{ "foo" | error }}`)
514+
} catch (err: unknown) {
515+
expect(LiquidError.is(err) && err.originalError).toHaveProperty('message', 'intended')
516+
}
517+
})
509518
})

0 commit comments

Comments
 (0)