diff --git a/packages/driver/cypress/integration/cypress/error_utils_spec.ts b/packages/driver/cypress/integration/cypress/error_utils_spec.ts index 7a5078b5c50..fcd5a0b81db 100644 --- a/packages/driver/cypress/integration/cypress/error_utils_spec.ts +++ b/packages/driver/cypress/integration/cypress/error_utils_spec.ts @@ -622,4 +622,18 @@ describe('driver/src/cypress/error_utils', () => { expect(stack).not.to.include('removeMeAndAbove') }) }) + + context('.wrapErr', () => { + [ + { value: undefined, label: 'undefined' }, + { value: null, label: 'null' }, + { value: '', label: 'empty string' }, + { value: true, label: 'boolean' }, + { value: 1, label: 'number' }, + ].forEach((err) => { + it(`returns undefined if err is ${err.label}`, () => { + expect($errUtils.wrapErr(err.value)).to.be.undefined + }) + }) + }) }) diff --git a/packages/driver/src/cypress/error_utils.ts b/packages/driver/src/cypress/error_utils.ts index 9c58d6950aa..3d001726ecf 100644 --- a/packages/driver/src/cypress/error_utils.ts +++ b/packages/driver/src/cypress/error_utils.ts @@ -52,8 +52,14 @@ const prepareErrorForSerialization = (err) => { return err } +// some errors, probably from user callbacks, might be boolean, number or falsy values +// which means serializing will not provide any useful context +const isSerializableError = (err) => { + return !!err && (typeof err === 'object' || typeof err === 'string') +} + const wrapErr = (err) => { - if (!err) return + if (!isSerializableError(err)) return prepareErrorForSerialization(err)