From 57ae40778e66b9cec3453fbe2fc9e1a022393398 Mon Sep 17 00:00:00 2001 From: Sarath Francis Date: Wed, 17 Jun 2026 01:05:31 -0400 Subject: [PATCH] fix(errors): default options so transform works without a second argument The errors format destructured its options parameter directly ((einfo, { stack, cause }) => ...), so calling transform with only an info argument threw 'Cannot destructure property stack of undefined'. This is the exact call shown in the README's Errors example (errorsFormat.transform(new Error('Oh no!'))). Default the options to an empty object (as timestamp, metadata and pretty-print already do) and destructure stack/cause from it. --- errors.js | 3 ++- test/errors.test.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/errors.js b/errors.js index b1d163b..aa297f3 100644 --- a/errors.js +++ b/errors.js @@ -11,7 +11,8 @@ const { LEVEL, MESSAGE } = require('triple-beam'); * * Optionally, the Error's `stack` and/or `cause` properties can also be appended to the `info` object. */ -module.exports = format((einfo, { stack, cause }) => { +module.exports = format((einfo, opts = {}) => { + const { stack, cause } = opts; if (einfo instanceof Error) { const info = Object.assign({}, einfo, { level: einfo.level, diff --git a/test/errors.test.js b/test/errors.test.js index 32ae79c..05cacd7 100644 --- a/test/errors.test.js +++ b/test/errors.test.js @@ -143,3 +143,14 @@ describe('errors()(Error)', () => { { immutable: false } )); }); + +describe('errors().transform called without options', () => { + it('does not throw when transform is called with a single argument', () => { + const errorsFormat = errors({ stack: true }); + const transformErr = new Error('Oh no!'); + const info = errorsFormat.transform(transformErr); + assume(info).is.an('object'); + assume(info.message).equals(transformErr.message); + assume(info[MESSAGE]).equals(transformErr.message); + }); +});