benjie / ouch-my-finger

16 stars 19 forks source link

Subscription error handling #12

Closed gitrojones closed 5 months ago

gitrojones commented 5 months ago

Hello,

Here's a fork with reproduction of the subscription issue I was running into involving error handling.

Setup:

  1. Setup .env, replacing DATABASE_URL with your own
  2. Run the server via yarn serve (Assumes Node20)

Steps:

  1. Create a subscription in Ruru for Foo
    foo(fooId: $fooId) {
    event
    }
    }
    --- VARIABLES
    {
    "fooId": 1
    }

Expectations: The error that is thrown in the subscribePlan should be routed to the maskError where the error can be handled/sanitized like in queries and mutations.

Reality: The error is mishandled and throws an internal error instead. The handler is assuming originalError exists in grafast/prepare.js > output.

image

Why is this a bug? An internal error is unhandled leading to the socket error.

Thanks!

benjie commented 5 months ago

Reproduced with

    makeExtendSchemaPlugin({
      typeDefs: gql`
        extend type Subscription {
          error: Int
        }
      `,
      plans: {
        Subscription: {
          error: {
            subscribePlan() {
              return lambda(constant(3), () => {
                throw new Error("Testing error");
              });
            },
          },
        },
      },
    }),
benjie commented 5 months ago

Closing in favour of https://github.com/graphile/crystal/issues/2080