Repository: cypress-io/cypress
File: packages/driver/src/cross-origin/origin_fn.ts (TypeScript)

Code before:
    // @ts-ignore
    window.__cySkipValidateConfig = skipConfigValidation || false

    // resync the config/env before running the origin:fn
    syncConfigToCurrentOrigin(config)
    syncEnvToCurrentOrigin(env)

    cy.state('onQueueEnd', () => {
      queueFinished = true
      setRunnableStateToPassed()
      Cypress.specBridgeCommunicator.toPrimary('queue:finished', {
        subject: cy.subject(),
      }, {
        syncGlobals: true,
      })
    })

    cy.state('onFail', (err) => {
      const currentAssertionUserInvocationStack = cy.state('current').get('currentAssertionCommand')?.get('userInvocationStack')
      const userInvocationStack = cy.state('current').get('userInvocationStack')

      setRunnableStateToPassed()
      if (queueFinished) {
        // If the queue is already finished, send this event instead because
        // the primary won't be listening for 'queue:finished' anymore
        Cypress.specBridgeCommunicator.toPrimary('uncaught:error', { err, userInvocationStack, currentAssertionUserInvocationStack })

        return
      }

      const currentAssertionUserInvocationStack = cy.state('current').get('currentAssertionCommand')?.get('userInvocationStack')
      const userInvocationStack = cy.state('current').get('userInvocationStack')

      cy.stop()
      Cypress.specBridgeCommunicator.toPrimary('queue:finished', { err, crossOriginUserInvocationStack: currentAssertionUserInvocationStack || userInvocationStack }, { syncGlobals: true })
    })

    // the name of this function is used to verify if privileged commands are
    // properly called. it shouldn't be removed and if the name is changed, it
    // needs to also be changed in server/lib/browsers/privileged-channel.js
    function invokeOriginFn (callback) {
      return window.eval(`(${callback})`)(args)
    }

    try {
      const callback = await getCallbackFn(fn, file)
      const value = invokeOriginFn(callback)

      // If we detect a non promise value with commands in queue, throw an error
      if (value && cy.queue.length > 0 && !value.then) {
        $errUtils.throwErrByPath('origin.callback_mixes_sync_and_async', {

Review comment (suggestion):
```suggestion
        Cypress.specBridgeCommunicator.toPrimary('uncaught:error', { err })
```

Code after:
    // @ts-ignore
    window.__cySkipValidateConfig = skipConfigValidation || false

    // resync the config/env before running the origin:fn
    syncConfigToCurrentOrigin(config)
    syncEnvToCurrentOrigin(env)

    cy.state('onQueueEnd', () => {
      queueFinished = true
      setRunnableStateToPassed()
      Cypress.specBridgeCommunicator.toPrimary('queue:finished', {
        subject: cy.subject(),
      }, {
        syncGlobals: true,
      })
    })

    cy.state('onFail', (err) => {
      setRunnableStateToPassed()
      if (queueFinished) {
        // If the queue is already finished, send this event instead because
        // the primary won't be listening for 'queue:finished' anymore
        Cypress.specBridgeCommunicator.toPrimary('uncaught:error', { err })

        return
      }

      const currentAssertionUserInvocationStack = cy.state('current').get('currentAssertionCommand')?.get('userInvocationStack')
      const userInvocationStack = cy.state('current').get('userInvocationStack')

      cy.stop()
      Cypress.specBridgeCommunicator.toPrimary('queue:finished', { err, crossOriginUserInvocationStack: currentAssertionUserInvocationStack || userInvocationStack }, { syncGlobals: true })
    })

    // the name of this function is used to verify if privileged commands are
    // properly called. it shouldn't be removed and if the name is changed, it
    // needs to also be changed in server/lib/browsers/privileged-channel.js
    function invokeOriginFn (callback) {
      return window.eval(`(${callback})`)(args)
    }

    try {
      const callback = await getCallbackFn(fn, file)
      const value = invokeOriginFn(callback)

      // If we detect a non promise value with commands in queue, throw an error
      if (value && cy.queue.length > 0 && !value.then) {
        $errUtils.throwErrByPath('origin.callback_mixes_sync_and_async', {
          args: { value: $utils.stringify(value) },
        })
      } else {