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
This commit is contained in:
Jakob Ackermann 2022-09-15 10:35:41 +01:00 committed by Copybot
parent 010476a60f
commit ee70dc4a19
2 changed files with 13 additions and 1 deletions

View file

@ -137,7 +137,7 @@ class OError extends Error {
const oError = /** @type{OError} */ (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) { if (Array.isArray(oError._oErrorTags) && oError._oErrorTags.length) {
stack += `\n${oError._oErrorTags.map(tag => tag.stack).join('\n')}` stack += `\n${oError._oErrorTags.map(tag => tag.stack).join('\n')}`

View file

@ -409,5 +409,17 @@ describe('utils', function () {
expect(OError.getFullInfo(error.cause)).to.eql({ foo: 1 }) 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',
])
})
}) })
}) })