From ee70dc4a1949fe8da023bcde48eec917ebe01dc4 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Thu, 15 Sep 2022 10:35:41 +0100 Subject: [PATCH] Merge pull request #9625 from overleaf/jpa-logging-no-stack [o-error] fallback from err.stack to err.message then '(no stack)' GitOrigin-RevId: 2b5e8af5791d92e618336a201f8c66ba23c8d46d --- libraries/o-error/index.js | 2 +- libraries/o-error/test/o-error-util.test.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libraries/o-error/index.js b/libraries/o-error/index.js index 7a208c9861..ef08b45f16 100644 --- a/libraries/o-error/index.js +++ b/libraries/o-error/index.js @@ -137,7 +137,7 @@ class OError extends Error { const oError = /** @type{OError} */ (error) - let stack = oError.stack || '(no stack)' + let stack = oError.stack || oError.message || '(no stack)' if (Array.isArray(oError._oErrorTags) && oError._oErrorTags.length) { stack += `\n${oError._oErrorTags.map(tag => tag.stack).join('\n')}` diff --git a/libraries/o-error/test/o-error-util.test.js b/libraries/o-error/test/o-error-util.test.js index d0b01a7fd7..c13f032541 100644 --- a/libraries/o-error/test/o-error-util.test.js +++ b/libraries/o-error/test/o-error-util.test.js @@ -409,5 +409,17 @@ describe('utils', function () { expect(OError.getFullInfo(error.cause)).to.eql({ foo: 1 }) } }) + + it('works when given non Error', function () { + expect(OError.getFullStack({ message: 'Foo' })).to.equal('Foo') + }) + + it('works when given non Error with tags', function () { + const error = OError.tag({ message: 'Foo: bar' }, 'baz') + expectFullStackWithoutStackFramesToEqual(error, [ + 'Foo: bar', + 'TaggedError: baz', + ]) + }) }) })