Skip to content

Commit

Permalink
fix: expose originalError from LiquidError, #742
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Aug 29, 2024
1 parent 62bb20e commit 86f6bf0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/util/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const TRAIT = '__liquidClass__'
export abstract class LiquidError extends Error {
public token!: Token
public context = ''
private originalError?: Error
public originalError?: Error
public constructor (err: Error | string, token: Token) {
/**
* note: for ES5 targeting, `this` will be replaced by return value of Error(),
Expand Down
11 changes: 10 additions & 1 deletion test/e2e/issues.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TopLevelToken, TagToken, Tokenizer, Context, Liquid, Drop, toValueSync } from '../..'
import { TopLevelToken, TagToken, Tokenizer, Context, Liquid, Drop, toValueSync, LiquidError } from '../..'
const LiquidUMD = require('../../dist/liquid.browser.umd.js').Liquid

describe('Issues', function () {
Expand Down Expand Up @@ -506,4 +506,13 @@ describe('Issues', function () {
expect(liquid.parseAndRender('{{ 113 | uniq }}')).resolves.toEqual('113')
expect(liquid.parseAndRender("{{ '113' | uniq }}")).resolves.toEqual('113')
})
it('Exposing originalError in LiquidError #742', () => {
const engine = new Liquid()
engine.registerFilter('error', () => { throw new Error('intended') })
try {
engine.parseAndRenderSync(`{{ "foo" | error }}`)
} catch (err: unknown) {
expect(LiquidError.is(err) && err.originalError).toHaveProperty('message', 'intended')
}
})
})

0 comments on commit 86f6bf0

Please sign in to comment.