diff --git a/src/util/error.ts b/src/util/error.ts index 0e169129ab..8fe76061df 100644 --- a/src/util/error.ts +++ b/src/util/error.ts @@ -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(), diff --git a/test/e2e/issues.spec.ts b/test/e2e/issues.spec.ts index d95f7ca8fa..d37d91104c 100644 --- a/test/e2e/issues.spec.ts +++ b/test/e2e/issues.spec.ts @@ -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 () { @@ -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') + } + }) })